enabled elastic

This commit is contained in:
Dmitriy Kuzmenko 2019-11-12 04:12:27 +03:00
parent e4061996a8
commit 2fe56d713d
3 changed files with 81 additions and 81 deletions

View File

@ -1 +1 @@
# from search_indexes.signals import update_document
from search_indexes.signals import update_document

View File

@ -1,77 +1,77 @@
# """Search indexes app signals."""
# from django.db.models.signals import post_save
# 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)
#
# if app_label == 'establishment':
# # 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)
#
#
# @receiver(post_save)
# def update_news(sender, **kwargs):
# from news.models import News
# app_label = sender._meta.app_label
# model_name = sender._meta.model_name
# instance = kwargs['instance']
#
# 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)
"""Search indexes app signals."""
from django.db.models.signals import post_save
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)
if app_label == 'establishment':
# 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)
@receiver(post_save)
def update_news(sender, **kwargs):
from news.models import News
app_label = sender._meta.app_label
model_name = sender._meta.model_name
instance = kwargs['instance']
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)

View File

@ -66,7 +66,7 @@ PROJECT_APPS = [
'partner.apps.PartnerConfig',
'product.apps.ProductConfig',
'recipe.apps.RecipeConfig',
# 'search_indexes.apps.SearchIndexesConfig',
'search_indexes.apps.SearchIndexesConfig',
'translation.apps.TranslationConfig',
'configuration.apps.ConfigurationConfig',
'timetable.apps.TimetableConfig',
@ -79,8 +79,8 @@ PROJECT_APPS = [
EXTERNAL_APPS = [
'corsheaders',
# 'django_elasticsearch_dsl',
# 'django_elasticsearch_dsl_drf',
'django_elasticsearch_dsl',
'django_elasticsearch_dsl_drf',
'django_filters',
'drf_yasg',
'fcm_django',