Okay use below in html
{{yourmodelnameinsmall_filter.form}}

Thanks & Regards
Shailesh Yadav
+91-9920886044

  [image: Linkedin] <https://in.linkedin.com/in/shailesh-yadav-b7ab89110>



On Wed, Jun 23, 2021 at 2:58 PM Aritra Ray <aritra...@gmail.com> wrote:

> 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, <shaileshyadav7...@gmail.com>
> wrote:
>
>> Can you help with what ERROR you are getting?
>>
>> Thanks & Regards
>> Shailesh Yadav
>> +91-9920886044
>>
>>   [image: Linkedin] <https://in.linkedin.com/in/shailesh-yadav-b7ab89110>
>>
>>
>>
>>
>> On Wed, Jun 23, 2021 at 2:25 PM Aritra Ray <aritra...@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.py
>>> class 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 = Items
>>>         fields = ['size', 'availability']
>>>
>>> #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>
>>>
>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAFecadtwZG0%3DLwE989gsFkusgAnAGkvEspF3i5WC1-uWO6OOHw%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAFecadtwZG0%3DLwE989gsFkusgAnAGkvEspF3i5WC1-uWO6OOHw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> 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+unsubscr...@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
>> <https://groups.google.com/d/msgid/django-users/CAMQ-AEXsJ%2B19X3aO740%3DD%2BZUhcEYujh2FWScZDXCqM4cB0Bikg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFecaduw28greFLXGqsTuit5JmCrzfHqawOU9HKvoojfXQLYtg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAFecaduw28greFLXGqsTuit5JmCrzfHqawOU9HKvoojfXQLYtg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMQ-AEXrqujnhn3q_629ZyjCbrS31j7mtqAt9br0psKPSB53dQ%40mail.gmail.com.

Reply via email to