Products search signals & filters
This commit is contained in:
parent
81ebd5764c
commit
46df31cbed
|
|
@ -11,44 +11,20 @@ def update_document(sender, **kwargs):
|
||||||
model_name = sender._meta.model_name
|
model_name = sender._meta.model_name
|
||||||
instance = kwargs['instance']
|
instance = kwargs['instance']
|
||||||
|
|
||||||
if app_label == 'location':
|
app_label_model_name_to_filter = {
|
||||||
if model_name == 'country':
|
('location','country'): 'address__city__country',
|
||||||
establishments = Establishment.objects.filter(
|
('location','city'): 'address__city',
|
||||||
address__city__country=instance)
|
('location', 'address'): 'address',
|
||||||
for establishment in establishments:
|
|
||||||
registry.update(establishment)
|
|
||||||
if model_name == 'city':
|
|
||||||
establishments = Establishment.objects.filter(
|
|
||||||
address__city=instance)
|
|
||||||
for establishment in establishments:
|
|
||||||
registry.update(establishment)
|
|
||||||
if model_name == 'address':
|
|
||||||
establishments = Establishment.objects.filter(
|
|
||||||
address=instance)
|
|
||||||
for establishment in establishments:
|
|
||||||
registry.update(establishment)
|
|
||||||
|
|
||||||
if app_label == 'establishment':
|
|
||||||
# todo: remove after migration
|
# todo: remove after migration
|
||||||
from establishment import models as establishment_models
|
('establishment', 'establishmenttype'): 'establishment_type',
|
||||||
if model_name == 'establishmenttype':
|
('establishment', 'establishmentsubtype'): 'establishment_subtypes',
|
||||||
if isinstance(instance, establishment_models.EstablishmentType):
|
('tag', 'tag'): 'tags',
|
||||||
establishments = Establishment.objects.filter(
|
}
|
||||||
establishment_type=instance)
|
filter_name = app_label_model_name_to_filter.get((app_label, model_name))
|
||||||
for establishment in establishments:
|
if filter_name:
|
||||||
registry.update(establishment)
|
qs = Establishment.objects.filter(**{filter_name: instance})
|
||||||
if model_name == 'establishmentsubtype':
|
for product in qs:
|
||||||
if isinstance(instance, establishment_models.EstablishmentSubType):
|
registry.update(product)
|
||||||
establishments = Establishment.objects.filter(
|
|
||||||
establishment_subtypes=instance)
|
|
||||||
for establishment in establishments:
|
|
||||||
registry.update(establishment)
|
|
||||||
|
|
||||||
if app_label == 'tag':
|
|
||||||
if model_name == 'tag':
|
|
||||||
establishments = Establishment.objects.filter(tags=instance)
|
|
||||||
for establishment in establishments:
|
|
||||||
registry.update(establishment)
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save)
|
@receiver(post_save)
|
||||||
|
|
@ -57,21 +33,35 @@ def update_news(sender, **kwargs):
|
||||||
app_label = sender._meta.app_label
|
app_label = sender._meta.app_label
|
||||||
model_name = sender._meta.model_name
|
model_name = sender._meta.model_name
|
||||||
instance = kwargs['instance']
|
instance = kwargs['instance']
|
||||||
|
app_label_model_name_to_filter = {
|
||||||
|
('location','country'): 'country',
|
||||||
|
('news','newstype'): 'news_type',
|
||||||
|
('tag', 'tag'): 'tags',
|
||||||
|
}
|
||||||
|
filter_name = app_label_model_name_to_filter.get((app_label, model_name))
|
||||||
|
if filter_name:
|
||||||
|
qs = News.objects.filter(**{filter_name: instance})
|
||||||
|
for product in qs:
|
||||||
|
registry.update(product)
|
||||||
|
|
||||||
if app_label == 'location':
|
|
||||||
if model_name == 'country':
|
|
||||||
qs = News.objects.filter(country=instance)
|
|
||||||
for news in qs:
|
|
||||||
registry.update(news)
|
|
||||||
|
|
||||||
if app_label == 'news':
|
@receiver(post_save)
|
||||||
if model_name == 'newstype':
|
def update_product(sender, **kwargs):
|
||||||
qs = News.objects.filter(news_type=instance)
|
from product.models import Product
|
||||||
for news in qs:
|
app_label = sender._meta.app_label
|
||||||
registry.update(news)
|
model_name = sender._meta.model_name
|
||||||
|
instance = kwargs['instance']
|
||||||
if app_label == 'tag':
|
app_label_model_name_to_filter = {
|
||||||
if model_name == 'tag':
|
('product','productstandard'): 'standards',
|
||||||
qs = News.objects.filter(tags=instance)
|
('product', 'producttype'): 'product_type',
|
||||||
for news in qs:
|
('tag','tag'): 'tags',
|
||||||
registry.update(news)
|
('location', 'wineregion'): 'wine_region',
|
||||||
|
('location', 'winesubregion'): 'wine_sub_region',
|
||||||
|
('location', 'winevillage'): 'wine_village',
|
||||||
|
('establishment', 'establishment'): 'establishment',
|
||||||
|
}
|
||||||
|
filter_name = app_label_model_name_to_filter.get((app_label, model_name))
|
||||||
|
if filter_name:
|
||||||
|
qs = Product.objects.filter(**{filter_name: instance})
|
||||||
|
for product in qs:
|
||||||
|
registry.update(product)
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,6 @@ class ProductDocumentViewSet(BaseDocumentViewSet):
|
||||||
pagination_class = ProjectMobilePagination
|
pagination_class = ProjectMobilePagination
|
||||||
permission_classes = (permissions.AllowAny,)
|
permission_classes = (permissions.AllowAny,)
|
||||||
serializer_class = serializers.ProductDocumentSerializer
|
serializer_class = serializers.ProductDocumentSerializer
|
||||||
ordering = ('id',)
|
|
||||||
|
|
||||||
# def get_queryset(self):
|
# def get_queryset(self):
|
||||||
# qs = super(ProductDocumentViewSet, self).get_queryset()
|
# qs = super(ProductDocumentViewSet, self).get_queryset()
|
||||||
|
|
@ -218,16 +217,47 @@ class ProductDocumentViewSet(BaseDocumentViewSet):
|
||||||
]
|
]
|
||||||
|
|
||||||
search_fields = {
|
search_fields = {
|
||||||
|
'name': {'fuzziness': 'auto:3,4',
|
||||||
|
'boost': '2'},
|
||||||
|
'transliterated_name': {'fuzziness': 'auto:3,4',
|
||||||
|
'boost': '2'},
|
||||||
|
'index_name': {'fuzziness': 'auto:3,4',
|
||||||
|
'boost': '2'},
|
||||||
|
'description': {'fuzziness': 'auto'},
|
||||||
}
|
}
|
||||||
translated_search_fields = (
|
translated_search_fields = (
|
||||||
|
'description',
|
||||||
)
|
)
|
||||||
|
|
||||||
filter_fields = {
|
filter_fields = {
|
||||||
'slug': 'slug',
|
'slug': 'slug',
|
||||||
'tag': {
|
'tags_id': {
|
||||||
'field': 'tags.id',
|
'field': 'tags.id',
|
||||||
'lookups': [constants.LOOKUP_QUERY_IN]
|
'lookups': [constants.LOOKUP_QUERY_IN]
|
||||||
},
|
},
|
||||||
|
'wine_colors_id': {
|
||||||
|
'field': 'wine_colors.id',
|
||||||
|
'lookups': [
|
||||||
|
constants.LOOKUP_QUERY_IN,
|
||||||
|
constants.LOOKUP_QUERY_EXCLUDE,
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'wine_from_country_code': {
|
||||||
|
'field': 'wine_region.country.code',
|
||||||
|
},
|
||||||
|
'for_establishment': {
|
||||||
|
'field': 'establishment.slug',
|
||||||
|
},
|
||||||
|
'type': {
|
||||||
|
'field': 'product_type.index_name',
|
||||||
|
},
|
||||||
|
'subtype': {
|
||||||
|
'field': 'subtypes.index_name',
|
||||||
|
'lookups': [
|
||||||
|
constants.LOOKUP_QUERY_IN,
|
||||||
|
constants.LOOKUP_QUERY_EXCLUDE,
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
geo_spatial_filter_fields = {
|
geo_spatial_filter_fields = {
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user