From c570cfdadd03f6ac338c6915afd4aee6e5119cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=93=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=D1=85?= Date: Wed, 20 Nov 2019 15:29:03 +0300 Subject: [PATCH 1/2] Fix --- apps/product/management/commands/add_product_tag.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/product/management/commands/add_product_tag.py b/apps/product/management/commands/add_product_tag.py index 589c7a83..18a2da21 100644 --- a/apps/product/management/commands/add_product_tag.py +++ b/apps/product/management/commands/add_product_tag.py @@ -1,6 +1,7 @@ from django.core.management.base import BaseCommand from django.db import connections from establishment.management.commands.add_position import namedtuplefetchall +from django.db.models import Q from tag.models import Tag, TagCategory from product.models import Product, ProductType from tqdm import tqdm @@ -67,8 +68,7 @@ class Command(BaseCommand): with connections['legacy'].cursor() as cursor: cursor.execute(''' select - DISTINCT - m.id as old_id, + DISTINCT trim(CONVERT(m.value USING utf8)) as tag_value, trim(CONVERT(v.key_name USING utf8)) as tag_category FROM product_metadata m @@ -103,6 +103,14 @@ class Command(BaseCommand): p.tags.clear() print('End clear tags product') + + def remove_tags(self): + print('Begin delete many tags') + Tag.objects.\ + filter(news__isnull=True, establishments__isnull=True).delete() + print('End delete many tags') + + def product_sql(self): with connections['legacy'].cursor() as cursor: cursor.execute(''' @@ -145,6 +153,7 @@ class Command(BaseCommand): def handle(self, *args, **kwargs): self.remove_tags_product() + self.remove_tags() self.add_category_tag() self.add_type_product_category() self.add_tag() From 5a55fa82a2ae1961048c2e3257b3d3b89ebefe3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=93=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=D1=85?= Date: Wed, 20 Nov 2019 15:32:36 +0300 Subject: [PATCH 2/2] Codestyle --- apps/product/management/commands/add_product_tag.py | 1 - project/settings/base.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/product/management/commands/add_product_tag.py b/apps/product/management/commands/add_product_tag.py index 18a2da21..dc54f35c 100644 --- a/apps/product/management/commands/add_product_tag.py +++ b/apps/product/management/commands/add_product_tag.py @@ -1,7 +1,6 @@ from django.core.management.base import BaseCommand from django.db import connections from establishment.management.commands.add_position import namedtuplefetchall -from django.db.models import Q from tag.models import Tag, TagCategory from product.models import Product, ProductType from tqdm import tqdm diff --git a/project/settings/base.py b/project/settings/base.py index 165dffec..9c365b52 100644 --- a/project/settings/base.py +++ b/project/settings/base.py @@ -503,4 +503,4 @@ ESTABLISHMENT_CHOSEN_TAGS = ['gastronomic', 'en_vogue', 'terrace', 'streetfood', NEWS_CHOSEN_TAGS = ['eat', 'drink', 'cook', 'style', 'international', 'event', 'partnership'] INTERNATIONAL_COUNTRY_CODES = ['www', 'main', 'next'] -#ELASTICSEARCH_DSL_AUTOSYNC = False \ No newline at end of file +ELASTICSEARCH_DSL_AUTOSYNC = False \ No newline at end of file