Added current product exclude
This commit is contained in:
parent
1372538acf
commit
0c5140d359
|
|
@ -9,6 +9,7 @@ class ProductFilterSet(filters.FilterSet):
|
||||||
"""Product filter set."""
|
"""Product filter set."""
|
||||||
|
|
||||||
establishment_id = filters.NumberFilter()
|
establishment_id = filters.NumberFilter()
|
||||||
|
current_product = filters.CharFilter(method='without_current_product')
|
||||||
product_type = filters.CharFilter(method='by_product_type')
|
product_type = filters.CharFilter(method='by_product_type')
|
||||||
product_subtype = filters.CharFilter(method='by_product_subtype')
|
product_subtype = filters.CharFilter(method='by_product_subtype')
|
||||||
|
|
||||||
|
|
@ -21,6 +22,11 @@ class ProductFilterSet(filters.FilterSet):
|
||||||
'product_subtype',
|
'product_subtype',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def without_current_product(self, queryset, name, value):
|
||||||
|
if value not in EMPTY_VALUES:
|
||||||
|
return queryset.without_current_product(value)
|
||||||
|
return queryset
|
||||||
|
|
||||||
def by_product_type(self, queryset, name, value):
|
def by_product_type(self, queryset, name, value):
|
||||||
if value not in EMPTY_VALUES:
|
if value not in EMPTY_VALUES:
|
||||||
return queryset.by_product_type(value)
|
return queryset.by_product_type(value)
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,11 @@ class ProductQuerySet(models.QuerySet):
|
||||||
def wines(self):
|
def wines(self):
|
||||||
return self.filter(type__index_name__icontains=ProductType.WINE)
|
return self.filter(type__index_name__icontains=ProductType.WINE)
|
||||||
|
|
||||||
|
def without_current_product(self, current_product: str):
|
||||||
|
"""Exclude by current product."""
|
||||||
|
kwargs = {'pk': int(current_product)} if current_product.isdigit() else {'slug': current_product}
|
||||||
|
return self.exclude(**kwargs)
|
||||||
|
|
||||||
def by_product_type(self, product_type: str):
|
def by_product_type(self, product_type: str):
|
||||||
"""Filter by type."""
|
"""Filter by type."""
|
||||||
return self.filter(product_type__index_name__icontains=product_type)
|
return self.filter(product_type__index_name__icontains=product_type)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user