I
I
Ivan2018-09-27 09:10:54
Django
Ivan, 2018-09-27 09:10:54

Python/Django Product filter on website?

I'm learning django and I'm stuck on implementing filters on the product listing page.
Models:

class Products(models.Model):
date_create = models.DateTimeField(auto_now_add=True, verbose_name='Дата создания')
date_edite = models.DateTimeField(auto_now=True, verbose_name='Дата изменения')
category = TreeForeignKey('Category', on_delete=models.SET_NULL, null=True, blank=True, verbose_name="Категория", db_index=True)
nazvanie = models.CharField(max_length=350, verbose_name='Название', db_index=True)
kodtovara = models.CharField(max_length=50, verbose_name='Фирменный код', null=True, blank=True, db_index=True)
article = models.CharField(max_length=50, verbose_name='Артикул', null=True, blank=True, db_index=True)
slug = models.SlugField(blank=True)


class PropertiesProduct(models.Model):
nazvanie = models.CharField(max_length=500, verbose_name='Название', db_index=True)
slug_nazvanie = models.SlugField(blank=True)
znachenie = models.CharField(max_length=500, verbose_name='Значение', db_index=True)
slug_znachenie = models.SlugField(blank=True)
detail = models.BooleanField(null=True, blank=True, verbose_name='Использовать как свойство в описании товара', db_index=True, default=True)
filter = models.BooleanField(null=True, blank=True, verbose_name='Использовать для фильтра', db_index=True, default=True)
register = models.BooleanField(null=True, blank=True, verbose_name='Расширенные свойства', db_index=True, default=False)
tovary = models.ForeignKey('Products', on_delete=models.SET_NULL, null=True, verbose_name='Товар', db_index=True)

The product property model has string fields for storing product property names and values, and a product binding field. The properties are placed in a separate table, since they will arrive from 1C and must be constantly added / deleted / edited when exchanging with 1C. In the DB, the properties are stored as in the photo from the admin panel.
5bac7430f11e8656949133.jpeg
Model of product properties
In the front-end, I want to display filtering, for example, as in the photo:
5bac743b55db8686992836.jpeg
Standard filter
I don’t know from which side to approach the implementation, maybe someone will tell you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-09-27
@Letivan

Read about EAV , look at implementations . Then read about faceted search and google its implementations. And then decide what is best suited specifically for your project and whether it is worth cutting your own solution or taking a ready-made one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question