K
K
kzr2014-12-16 20:47:20
Django
kzr, 2014-12-16 20:47:20

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

2 answer(s)
A
Ali Aliyev, 2014-12-17
@kzr

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

filters.py (we work in the same way as with a regular form)
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'],
                 }

V
Vladislav, 2014-12-16
@RGV

It can be implemented on the server side (Python/Django), it can be implemented on the client side (JavaScript).
How? Many ways.
JavaScript option: Isotope.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question