small refactoring

This commit is contained in:
Anatoly 2019-10-28 13:11:07 +03:00
parent 65e7c965e4
commit ed09ee78cc
2 changed files with 14 additions and 14 deletions

View File

@ -9,26 +9,26 @@ class ProductListFilterSet(filters.FilterSet):
"""Product filter set."""
establishment_id = filters.NumberFilter()
type = filters.ChoiceFilter(method='by_type',
choices=models.ProductType.INDEX_NAME_TYPES)
subtype = filters.ChoiceFilter(method='by_subtype',
choices=models.ProductSubType.INDEX_NAME_TYPES)
product_type = filters.ChoiceFilter(method='by_product_type',
choices=models.ProductType.INDEX_NAME_TYPES)
product_subtype = filters.ChoiceFilter(method='by_product_subtype',
choices=models.ProductSubType.INDEX_NAME_TYPES)
class Meta:
"""Meta class."""
model = models.Product
fields = [
'establishment_id',
'type',
'subtype',
'product_type',
'product_subtype',
]
def by_type(self, queryset, name, value):
def by_product_type(self, queryset, name, value):
if value not in EMPTY_VALUES:
return queryset.by_type(value)
return queryset.by_product_type(value)
return queryset
def by_subtype(self, queryset, name, value):
def by_product_subtype(self, queryset, name, value):
if value not in EMPTY_VALUES:
return queryset.by_subtype(value)
return queryset.by_product_subtype(value)
return queryset

View File

@ -91,13 +91,13 @@ class ProductQuerySet(models.QuerySet):
def wines(self):
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."""
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."""
return self.filter(subtypes__index_name=subtype)
return self.filter(subtypes__index_name=product_subtype)
class Product(TranslatedFieldsMixin, BaseAttributes):