Chosen tags for artisans

This commit is contained in:
Kuroshini 2019-10-16 14:11:07 +03:00
parent 0d2f961ad5
commit 8641188c45
2 changed files with 18 additions and 1 deletions

View File

@ -52,11 +52,21 @@ class TagCategoryFilterSet(TagsBaseFilterSet):
class TagsFilterSet(TagsBaseFilterSet):
"""Chosen tags filterset."""
establishment_type = filters.CharFilter(method='by_establishment_type')
class Meta:
"""Meta class."""
model = models.Tag
fields = ('type',)
fields = (
'type',
'establishment_type',
)
def by_establishment_type(self, queryset, name, value):
if value == EstablishmentType.ARTISAN:
return models.Tag.objects.by_category_index_name('shop_category')
return queryset.by_establishment_type(value)
# TMP TODO remove it later
# Временный хардкод для демонстрации 4 ноября, потом удалить!
@ -71,3 +81,4 @@ class TagsFilterSet(TagsBaseFilterSet):
queryset = queryset.for_establishments().filter(value__in=settings.ESTABLISHMENT_CHOSEN_TAGS).distinct(
'value')
return queryset

View File

@ -19,9 +19,15 @@ class TagQuerySet(models.QuerySet):
return self.filter(models.Q(category__establishment_types__isnull=False) |
models.Q(category__establishment_subtypes__isnull=False))
def by_category_index_name(self, index_name):
return self.filter(category__index_name=index_name)
def order_by_priority(self):
return self.order_by('chosentagsettings__priority')
def by_establishment_type(self, index_name):
return self.filter(category__establishment_types__index_name=index_name)
class Tag(TranslatedFieldsMixin, models.Model):
"""Tag model."""