This isn't working. When we are supplying a filter, the html is displaying all the products irrespective of the requested.
On Wed, 23 Jun, 2021, 2:57 pm Shailesh Yadav, <shaileshyadav7958@gmail.com> wrote:
--On Wed, Jun 23, 2021 at 2:25 PM Aritra Ray <aritra805@gmail.com> wrote:Hi,--I've been trying to introduce a filter system in my Django-ecommerce website and I've been struggling despite reading the documents, etc. I am using 'django-filter' and below are filters.py, models.py, views.py and the template. To check out the project, follow the github link: https://github.com/First-project-01/Django-ecommerce.Will be grateful if anyone can sort this out. Thanks in advance.Regards,Aritra#filters.pyclass ProductFilter(django_filters.FilterSet):price = django_filters.NumberFilter()price__gt = django_filters.NumberFilter(field_name='price', lookup_expr='gt')price__lt = django_filters.NumberFilter(field_name='price', lookup_expr='lt')class Meta:model = Itemsfields = ['size', 'availability']#views.py#models.pyclass Product(ListView):model = Itemspaginate_by = 6template_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 contextAVAILABILITY = (('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>
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFecadtwZG0%3DLwE989gsFkusgAnAGkvEspF3i5WC1-uWO6OOHw%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMQ-AEXsJ%2B19X3aO740%3DD%2BZUhcEYujh2FWScZDXCqM4cB0Bikg%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFecaduw28greFLXGqsTuit5JmCrzfHqawOU9HKvoojfXQLYtg%40mail.gmail.com.
No comments:
Post a Comment