Tag types

This commit is contained in:
Kuroshini 2019-10-16 14:11:07 +03:00
parent ca61359a81
commit bff533e7d5
3 changed files with 16 additions and 15 deletions

View File

@ -89,10 +89,6 @@ class EstablishmentDocumentViewSet(BaseDocumentViewSet):
search_fields = {
'name': {'fuzziness': 'auto:2,5',
'boost': 4},
'transliterated_name': {'fuzziness': 'auto:2,5',
'boost': 3},
'index_name': {'fuzziness': 'auto:2,5',
'boost': 2},
'description': {'fuzziness': 'auto:2,5'},
}
translated_search_fields = (
@ -199,7 +195,7 @@ class ProductDocumentViewSet(BaseDocumentViewSet):
"""Product document ViewSet."""
document = ProductDocument
lookup_field = 'slug'
# lookup_field = 'slug'
pagination_class = ProjectMobilePagination
permission_classes = (permissions.AllowAny,)
serializer_class = serializers.ProductDocumentSerializer
@ -212,8 +208,8 @@ class ProductDocumentViewSet(BaseDocumentViewSet):
filter_backends = [
FilteringFilterBackend,
filters.CustomSearchFilterBackend,
GeoSpatialFilteringFilterBackend,
DefaultOrderingFilterBackend,
# GeoSpatialFilteringFilterBackend,
# DefaultOrderingFilterBackend,
]
search_fields = {
@ -221,10 +217,9 @@ class ProductDocumentViewSet(BaseDocumentViewSet):
'boost': 4},
'transliterated_name': {'fuzziness': 'auto:2,5',
'boost': 3},
'index_name': {'fuzziness': 'auto:2,5',
'boost': 2},
'description': {'fuzziness': 'auto:2,5'},
}
translated_search_fields = (
'description',
)
@ -248,9 +243,6 @@ class ProductDocumentViewSet(BaseDocumentViewSet):
'for_establishment': {
'field': 'establishment.slug',
},
'type': {
'field': 'product_type.index_name',
},
'product_type': {
'field': 'product_type.index_name',
},
@ -262,5 +254,5 @@ class ProductDocumentViewSet(BaseDocumentViewSet):
]
}
}
geo_spatial_filter_fields = {
}
# geo_spatial_filter_fields = {
# }

View File

@ -31,13 +31,18 @@ class TagCategoryFilterSet(TagsBaseFilterSet):
"""TagCategory filterset."""
establishment_type = filters.CharFilter(method='by_establishment_type')
product_type = filters.CharFilter(method='by_product_type')
class Meta:
"""Meta class."""
model = models.TagCategory
fields = ('type',
'establishment_type', )
'establishment_type',
'product_type', )
def by_product_type(self, queryset, name, value):
return queryset.by_product_type(value)
# todo: filter by establishment type
def by_establishment_type(self, queryset, name, value):

View File

@ -100,6 +100,10 @@ class TagCategoryQuerySet(models.QuerySet):
"""Filter by establishment type index name."""
return self.filter(establishment_types__index_name=index_name)
def by_product_type(self, index_name):
"""Filter by product type index name."""
return self.filter(product_types__index_name=index_name)
def with_tags(self, switcher=True):
"""Filter by existing tags."""
return self.exclude(tags__isnull=switcher)