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
|
||||
instance = kwargs['instance']
|
||||
|
||||
if app_label == 'location':
|
||||
if model_name == 'country':
|
||||
establishments = Establishment.objects.filter(
|
||||
address__city__country=instance)
|
||||
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':
|
||||
app_label_model_name_to_filter = {
|
||||
('location','country'): 'address__city__country',
|
||||
('location','city'): 'address__city',
|
||||
('location', 'address'): 'address',
|
||||
# todo: remove after migration
|
||||
from establishment import models as establishment_models
|
||||
if model_name == 'establishmenttype':
|
||||
if isinstance(instance, establishment_models.EstablishmentType):
|
||||
establishments = Establishment.objects.filter(
|
||||
establishment_type=instance)
|
||||
for establishment in establishments:
|
||||
registry.update(establishment)
|
||||
if model_name == 'establishmentsubtype':
|
||||
if isinstance(instance, establishment_models.EstablishmentSubType):
|
||||
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)
|
||||
('establishment', 'establishmenttype'): 'establishment_type',
|
||||
('establishment', 'establishmentsubtype'): 'establishment_subtypes',
|
||||
('tag', 'tag'): 'tags',
|
||||
}
|
||||
filter_name = app_label_model_name_to_filter.get((app_label, model_name))
|
||||
if filter_name:
|
||||
qs = Establishment.objects.filter(**{filter_name: instance})
|
||||
for product in qs:
|
||||
registry.update(product)
|
||||
|
||||
|
||||
@receiver(post_save)
|
||||
|
|
@ -57,21 +33,35 @@ def update_news(sender, **kwargs):
|
|||
app_label = sender._meta.app_label
|
||||
model_name = sender._meta.model_name
|
||||
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':
|
||||
if model_name == 'newstype':
|
||||
qs = News.objects.filter(news_type=instance)
|
||||
for news in qs:
|
||||
registry.update(news)
|
||||
|
||||
if app_label == 'tag':
|
||||
if model_name == 'tag':
|
||||
qs = News.objects.filter(tags=instance)
|
||||
for news in qs:
|
||||
registry.update(news)
|
||||
@receiver(post_save)
|
||||
def update_product(sender, **kwargs):
|
||||
from product.models import Product
|
||||
app_label = sender._meta.app_label
|
||||
model_name = sender._meta.model_name
|
||||
instance = kwargs['instance']
|
||||
app_label_model_name_to_filter = {
|
||||
('product','productstandard'): 'standards',
|
||||
('product', 'producttype'): 'product_type',
|
||||
('tag','tag'): 'tags',
|
||||
('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
|
||||
permission_classes = (permissions.AllowAny,)
|
||||
serializer_class = serializers.ProductDocumentSerializer
|
||||
ordering = ('id',)
|
||||
|
||||
# def get_queryset(self):
|
||||
# qs = super(ProductDocumentViewSet, self).get_queryset()
|
||||
|
|
@ -218,16 +217,47 @@ class ProductDocumentViewSet(BaseDocumentViewSet):
|
|||
]
|
||||
|
||||
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 = (
|
||||
'description',
|
||||
)
|
||||
|
||||
filter_fields = {
|
||||
'slug': 'slug',
|
||||
'tag': {
|
||||
'tags_id': {
|
||||
'field': 'tags.id',
|
||||
'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 = {
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user