price_level & toque_number settings
This commit is contained in:
parent
6e4e1b214d
commit
2908286e6c
|
|
@ -0,0 +1 @@
|
||||||
|
from search_indexes.signals import update_document
|
||||||
|
|
@ -14,7 +14,8 @@ EstablishmentIndex.settings(number_of_shards=1, number_of_replicas=1)
|
||||||
class EstablishmentDocument(Document):
|
class EstablishmentDocument(Document):
|
||||||
"""Establishment document."""
|
"""Establishment document."""
|
||||||
|
|
||||||
description = fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES)
|
description = fields.ObjectField(attr='description_indexing',
|
||||||
|
properties=OBJECT_FIELD_PROPERTIES)
|
||||||
tags = fields.ObjectField(
|
tags = fields.ObjectField(
|
||||||
properties={
|
properties={
|
||||||
'id': fields.IntegerField(attr='id'),
|
'id': fields.IntegerField(attr='id'),
|
||||||
|
|
@ -56,13 +57,9 @@ class EstablishmentDocument(Document):
|
||||||
fields = (
|
fields = (
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'name',
|
||||||
'public_mark',
|
|
||||||
'toque_number',
|
'toque_number',
|
||||||
'price_level',
|
'price_level',
|
||||||
)
|
)
|
||||||
|
|
||||||
def prepare_description(self, instance):
|
|
||||||
return instance.description
|
|
||||||
|
|
||||||
def prepare_tags(self, instance):
|
def prepare_tags(self, instance):
|
||||||
return instance.tags_indexing
|
return instance.tags_indexing
|
||||||
|
|
|
||||||
33
apps/search_indexes/signals.py
Normal file
33
apps/search_indexes/signals.py
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
"""Search indexes app signals."""
|
||||||
|
from django.db.models.signals import post_save, post_delete
|
||||||
|
from django.dispatch import receiver
|
||||||
|
from django_elasticsearch_dsl.registries import registry
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save)
|
||||||
|
def update_document(sender, **kwargs):
|
||||||
|
from establishment.models import Establishment
|
||||||
|
app_label = sender._meta.app_label
|
||||||
|
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)
|
||||||
|
|
||||||
|
# todo: delete document
|
||||||
|
|
@ -66,6 +66,7 @@ class EstablishmentDocumentViewSet(BaseDocumentViewSet):
|
||||||
constants.LOOKUP_QUERY_GTE,
|
constants.LOOKUP_QUERY_GTE,
|
||||||
constants.LOOKUP_QUERY_LT,
|
constants.LOOKUP_QUERY_LT,
|
||||||
constants.LOOKUP_QUERY_LTE,
|
constants.LOOKUP_QUERY_LTE,
|
||||||
|
constants.LOOKUP_QUERY_IN,
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'price_level': {
|
'price_level': {
|
||||||
|
|
@ -76,6 +77,7 @@ class EstablishmentDocumentViewSet(BaseDocumentViewSet):
|
||||||
constants.LOOKUP_QUERY_GTE,
|
constants.LOOKUP_QUERY_GTE,
|
||||||
constants.LOOKUP_QUERY_LT,
|
constants.LOOKUP_QUERY_LT,
|
||||||
constants.LOOKUP_QUERY_LTE,
|
constants.LOOKUP_QUERY_LTE,
|
||||||
|
constants.LOOKUP_QUERY_IN,
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'country_id': {
|
'country_id': {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user