#views.py
class Product(ListView):
model = Items
paginate_by = 6
template_name = 'products.html'
def get_context_data(self, **kwargs):
context = super(Product, self).get_context_data(**kwargs)
context['filter'] = ProductFilter(self.request.GET, queryset=self.get_queryset())
return context
#models.py
AVAILABILITY = (
('Y', 'Available'),
('N', 'Out of Stock'),
)
SIZES = (
('K', 'King - 108 x 120'),
('Q', 'Queen - 90 x 108')
)
class Items(BaseModel):
title = models.CharField(max_length=100, null=True, blank=True)
price = models.FloatField(null=True, blank=True)
size = models.CharField(choices=SIZES, default=SIZES[0][0], max_length=1)
description = models.TextField(max_length=500)
availability = models.CharField(choices=AVAILABILITY, default=AVAILABILITY[0][0], max_length=1)
...
#product-list.html
<div class="col-md-3">
<form method="get">
{{ filter.form| crispy }}
<button type="submit">Search</button>
</form>
</div>