class Product(ListView):
model = Items
paginate_by = 6
template_name = 'products.html'
ordering = ["-id"]
def get_queryset(self):
queryset = super().get_queryset()
filter = ProductFilter(self.request.GET, queryset)
return filter.qs
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
queryset = self.get_queryset()
filter = ProductFilter(self.request.GET, queryset)
context["filter"] = filter
return context
class Items(BaseModel):
title = models.CharField(max_length=100, null=True, blank=True)
price = models.FloatField(null=True, blank=True)
discount_price = models.FloatField(max_length=100, blank=True, null=True)
description = models.TextField(max_length=500)
size = models.CharField(choices=SIZES, default=SIZES[0][0], max_length=10)
category = models.CharField(choices=CATEGORY, default=CATEGORY[0][0], max_length=1)
featured = models.BooleanField(default=False)
availability = models.CharField(choices=AVAILABILITY, default=AVAILABILITY[0][0], max_length=1)
image = ResizedImageField(upload_to="", null=True, blank=True)
slug = models.SlugField(max_length=100)
date_added = models.DateField(default=timezone.now)