Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- VIEWS VIEWS
- class ArtPostView(View):
- """ ART View list"""
- def get(self, request):
- artlist = ArtPost.objects.all().order_by("-published")
- category = Category.objects.all()
- context = {
- "artlist": artlist,
- "category": category
- }
- return render(request, 'artwapp/home.html', context)
- class ArtPostDetailView(View):
- """ single post by link"""
- def get(self, request, pk):
- art = ArtPost.objects.get(id=pk)
- context = {
- "art": art
- }
- return render(request, 'artwapp/art_detail.html', context)
- HTML HTML
- <div class="works">
- <div class="container">
- {% for category in category %}
- <div class="works__filter">
- <a class="works__filter-link" href="{{ category.url }}">{{ category.name }}</a>
- </div>
- {% endfor %}
- {% for art in artlist %}
- <div class="portfolio"><!-- Portfolio -->
- <div class="portfolio__col">
- <div class="work">
- <a class="work_image" href="{% url 'artw-detail' art.pk %}"><img src="{{ art.image.url }}" alt=""></a>
- <div class="work__content">
- <div class="work__cat">{{ art.category }}</div>
- <div class="work__title">
- {{ art.title }}
- <time class="work__date" datetime="2021-06-14 23:00">{{ art.published }}</time>
- </div>
- </div>
- </div>
- </div>
- </div>
- {% endfor %}
- </div>
- </div>
- {% endblock content %}
- MODELS MODELS
- class Category(models.Model):
- """ Web site's categories """
- name = models.CharField("Category", max_length=50)
- description = models.TextField("Description")
- url = models.SlugField(max_length=150, unique=True)
- def __str__(self):
- return self.name
- class Meta:
- verbose_name = "Category"
- verbose_name_plural = "Categories"
- class ArtPost(models.Model):
- """ Standart post class """
- author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
- title = models.CharField(max_length=50, null=False, blank=False)
- body = models.TextField(max_length=2000, null=False, blank=False)
- category = models.ForeignKey(Category, on_delete=models.CASCADE, verbose_name="Category")
- image = models.ImageField(upload_to='arts/', null=False, blank=False)
- published = models.DateTimeField(auto_now_add=True, verbose_name='Published day')
- def __str__(self):
- return self.title
- class Meta:
- verbose_name = "Post"
- verbose_name_plural = "Posts"
Advertisement
Add Comment
Please, Sign In to add comment