Answer the question
In order to leave comments, you need to log in
How to create a filter in django for an online store?
How to create a filter in django for an online store?
How to make a filter for an online store by several parameters?
Like here http://www.asos.com/en/Fashion-Online-39/Cat/pgeca...
Is it necessary to use js?
A dynamic filter is required. That is, so that the QuerySet is formed after the specified search conditions.
For example:
1 session:
Clicked on "Men's" -> all products filter(gender = "men's"), then
clicked on "jackets" -> all products came out filter(category = "jackets", gender = "men's"),
then clicked "size 50" -> all products came out filter (category = "jackets", gender = "men's", size = "size 50"),
then clicked on "jackets" -> all products came out filter( gender = "male", size = "size 50")
QuerySet should change depending on the filtering condition, how to transfer these conditions to the view? Need to use a form?
Maybe you need to save the QuerySet using pickle?
I will be glad to any answer!
because very few materiel)
Answer the question
In order to leave comments, you need to log in
Very good thing https://github.com/alex/django-filter easier to use with https://github.com/rasca/django-enhanced-cbv
Views.py example
from enhanced_cbv.views import ListFilteredView
from .models import MyModel
from .filters import MyFilter
class MiViewWithFilter(ListFilteredView):
filter_set = MyFilter
model = MyModel
import django_filters
from .models import MyModel
class MyFilter(django_filters.FilterSet):
def __init__(self, *args, **kwargs):
super(MyFilter, self).__init__(*args, **kwargs)
self.fields['email'].label = "New Email Label"
class Meta:
model = MyModel
fields = {'name': ['exact', 'icontains'],
'price': ['exact', 'gte', 'lte'],
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question