M
M
mr_drinkens892015-03-12 16:51:48
Django
mr_drinkens89, 2015-03-12 16:51:48

How to implement django product filters?

Can you tell me how to implement product filters?
Products can have many properties (for example, Type of oil - hydraulic), each product has its own set of properties.
You can follow the example of lfs, but it takes a very long time to score with your hands.
thank.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Anatoly Scherbakov, 2015-03-12
@Altaisoft

Have a look at django-hstore (assuming you can use PostgreSQL). This is a field in which you can store an arbitrary number of key-value pairs. Thus, you store fields common to all types of goods as ordinary model fields, and pack changing fields in hstore. These packed fields can even be searched, due to the fact that HStore is PostgreSQL's native data type.
You can also use the JSON type, which is also PostgreSQL specific. It differs from hstore in that the structure of the field can be tree-like and the values ​​can be typed (in fact, which is what JSON suggests). There are several packages that support this field in Django, you can google it.
Also an option is the mentioned EAV, but personally I really don't like this approach. Lack of type control, extremely low speed on large volumes and general ugliness of the solution. The SQL database was not created to be used as a key-value. It is better to slightly expand its capabilities with crutches like hstore.

A
Andrey K, 2015-03-12
@mututunus

https://github.com/mvpdev/django-eav

U
un1t, 2015-03-12
@un1t

I thought about this topic, how best to make such directories and came to the conclusion that any database can be used, and facets can be built using full-text search. I prefer elasticsearch.
Product properties can be stored in some JSONField. In fact, it makes absolutely no difference how to store them, the main thing is how to shove them into the index.
As an option, MongoDB can build faceted indexes. But the site usually needs a search engine anyway, so I do without Mongolian facets.

C
chemiron, 2015-03-20
@chemiron

I save these properties using eav-django. I do the search using Sphinx - I drive all the property values ​​​​for each product into the multi-attribute and then with a request to sphinx you can pull out a list of id products that match the filters. The advantage of this approach is that you can combine the selection by filters and full-text search.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question