small refactoring
This commit is contained in:
parent
65e7c965e4
commit
ed09ee78cc
|
|
@ -9,26 +9,26 @@ class ProductListFilterSet(filters.FilterSet):
|
||||||
"""Product filter set."""
|
"""Product filter set."""
|
||||||
|
|
||||||
establishment_id = filters.NumberFilter()
|
establishment_id = filters.NumberFilter()
|
||||||
type = filters.ChoiceFilter(method='by_type',
|
product_type = filters.ChoiceFilter(method='by_product_type',
|
||||||
choices=models.ProductType.INDEX_NAME_TYPES)
|
choices=models.ProductType.INDEX_NAME_TYPES)
|
||||||
subtype = filters.ChoiceFilter(method='by_subtype',
|
product_subtype = filters.ChoiceFilter(method='by_product_subtype',
|
||||||
choices=models.ProductSubType.INDEX_NAME_TYPES)
|
choices=models.ProductSubType.INDEX_NAME_TYPES)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
model = models.Product
|
model = models.Product
|
||||||
fields = [
|
fields = [
|
||||||
'establishment_id',
|
'establishment_id',
|
||||||
'type',
|
'product_type',
|
||||||
'subtype',
|
'product_subtype',
|
||||||
]
|
]
|
||||||
|
|
||||||
def by_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_type(value)
|
return queryset.by_product_type(value)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def by_subtype(self, queryset, name, value):
|
def by_product_subtype(self, queryset, name, value):
|
||||||
if value not in EMPTY_VALUES:
|
if value not in EMPTY_VALUES:
|
||||||
return queryset.by_subtype(value)
|
return queryset.by_product_subtype(value)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
|
||||||
|
|
@ -91,13 +91,13 @@ class ProductQuerySet(models.QuerySet):
|
||||||
def wines(self):
|
def wines(self):
|
||||||
return self.filter(type__index_name=ProductType.WINE)
|
return self.filter(type__index_name=ProductType.WINE)
|
||||||
|
|
||||||
def by_type(self, type: str):
|
def by_product_type(self, product_type: str):
|
||||||
"""Filter by type."""
|
"""Filter by type."""
|
||||||
return self.filter(product_type__index_name=type)
|
return self.filter(product_type__index_name=product_type)
|
||||||
|
|
||||||
def by_subtype(self, subtype: str):
|
def by_product_subtype(self, product_subtype: str):
|
||||||
"""Filter by subtype."""
|
"""Filter by subtype."""
|
||||||
return self.filter(subtypes__index_name=subtype)
|
return self.filter(subtypes__index_name=product_subtype)
|
||||||
|
|
||||||
|
|
||||||
class Product(TranslatedFieldsMixin, BaseAttributes):
|
class Product(TranslatedFieldsMixin, BaseAttributes):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user