Guest User

Untitled

a guest
Jun 15th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.99 KB | None | 0 0
  1. VIEWS  VIEWS
  2.  
  3. class ArtPostView(View):
  4.     """ ART View list"""
  5.  
  6.     def get(self, request):
  7.         artlist = ArtPost.objects.all().order_by("-published")
  8.         category = Category.objects.all()
  9.         context = {
  10.             "artlist": artlist,
  11.             "category": category
  12.         }
  13.         return render(request, 'artwapp/home.html', context)
  14.  
  15.  
  16.  
  17. class ArtPostDetailView(View):
  18.     """ single post by link"""
  19.  
  20.     def get(self, request, pk):
  21.         art = ArtPost.objects.get(id=pk)
  22.         context = {
  23.             "art": art
  24.         }
  25.         return render(request, 'artwapp/art_detail.html', context)
  26.  
  27.  
  28. HTML HTML
  29.  
  30. <div class="works">
  31.             <div class="container">
  32.  
  33.  
  34.                 {% for category in category %}
  35.                     <div class="works__filter">
  36.                         <a class="works__filter-link" href="{{ category.url }}">{{ category.name }}</a>
  37.                     </div>
  38.                 {% endfor %}
  39.  
  40.  
  41.                 {% for art in artlist %}
  42.                     <div class="portfolio"><!-- Portfolio -->
  43.                         <div class="portfolio__col">
  44.                             <div class="work">
  45.                                 <a class="work_image" href="{% url 'artw-detail' art.pk %}"><img src="{{ art.image.url }}" alt=""></a>
  46.                                 <div class="work__content">
  47.                                     <div class="work__cat">{{ art.category }}</div>
  48.                                     <div class="work__title">
  49.                                         {{ art.title }}
  50.                                         <time class="work__date" datetime="2021-06-14 23:00">{{ art.published }}</time>
  51.                                     </div>
  52.                                 </div>
  53.                             </div>
  54.                         </div>
  55.                     </div>
  56.                 {% endfor %}
  57.  
  58.  
  59.             </div>
  60.     </div>
  61. {% endblock content %}
  62.  
  63.  
  64.  
  65. MODELS MODELS
  66.  
  67. class Category(models.Model):
  68.     """ Web site's categories """
  69.     name = models.CharField("Category", max_length=50)
  70.     description = models.TextField("Description")
  71.     url = models.SlugField(max_length=150, unique=True)
  72.  
  73.     def __str__(self):
  74.         return self.name
  75.  
  76.     class Meta:
  77.         verbose_name = "Category"
  78.         verbose_name_plural = "Categories"
  79.  
  80.  
  81. class ArtPost(models.Model):
  82.     """ Standart post class """
  83.     author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
  84.     title = models.CharField(max_length=50, null=False, blank=False)
  85.     body = models.TextField(max_length=2000, null=False, blank=False)
  86.     category = models.ForeignKey(Category, on_delete=models.CASCADE, verbose_name="Category")
  87.     image = models.ImageField(upload_to='arts/', null=False, blank=False)
  88.     published = models.DateTimeField(auto_now_add=True, verbose_name='Published day')
  89.  
  90.     def __str__(self):
  91.         return self.title
  92.  
  93.     class Meta:
  94.         verbose_name = "Post"
  95.         verbose_name_plural = "Posts"
Advertisement
Add Comment
Please, Sign In to add comment