Есть модель категорий:
class Category(MPTTModel):
name = models.CharField(max_length=100, unique=True)
parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True)
description = models.TextField(blank=True, default='')
visible = models.BooleanField(default=True)
products_count = models.IntegerField(default=0, editable=True)
products_count_cache = models.PositiveIntegerField(default=0)
seo_name = models.SlugField(max_length=105)
seo_title = models.CharField(max_length=255, blank=True, default='')
seo_desc = models.TextField(blank=True, default='')
seo_keywords = models.TextField(blank=True, default='')
def __str__(self):
return self.name
class MPTTMeta:
order_insertion_by = ['name']
Сериализатор:
class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Category
fields = ('name','parent','description','visible','products_count',
'products_count_cache','seo_name','seo_title','seo_desc','seo_keywords', 'children')
depth = 2
Сейчас фильтрую так, но в выборку не попадают предметы из подкатегорий:
class ProductFilter(django_filters.rest_framework.FilterSet):
min_price = django_filters.NumberFilter(name="price", lookup_expr='gte')
max_price = django_filters.NumberFilter(name="price", lookup_expr='lte')
category_filter = django_filters.CharFilter(name='category__seo_name', lookup_expr='icontains')
vendors = NumberInFilter(name='vendor__name', lookup_expr='in', widget=django_filters.widgets.CSVWidget())
shops = NumberInFilter(name='shop__name', lookup_expr='in', widget=django_filters.widgets.CSVWidget())
free_deliverys = django_filters.BooleanFilter(name='free_delivery', widget=django_filters.widgets.BooleanWidget())
class Meta:
model = Product
fields = ['category_filter', 'min_price', 'max_price', 'vendors', 'shops', 'free_deliverys']
Как сделать так, что б в структуре:
при выборе Русской кухни в выборку попадали и предметы с категорией "Уха" ?