From 74c1b7069a22a3ce6c42f09a79622dbd617246bb Mon Sep 17 00:00:00 2001 From: Dmitriy Kuzmenko Date: Thu, 21 Nov 2019 00:23:17 +0300 Subject: [PATCH] fix product tags --- apps/product/management/commands/add_product_tag.py | 9 ++++----- project/settings/base.py | 2 +- project/settings/local.py | 10 +++++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/apps/product/management/commands/add_product_tag.py b/apps/product/management/commands/add_product_tag.py index dc54f35c..6377fcac 100644 --- a/apps/product/management/commands/add_product_tag.py +++ b/apps/product/management/commands/add_product_tag.py @@ -40,7 +40,6 @@ class Command(BaseCommand): TagCategory.objects.bulk_create(objects) self.stdout.write(self.style.WARNING(f'Add or get tag category objects.')) - def product_type_category_sql(self): with connections['legacy'].cursor() as cursor: cursor.execute(''' @@ -56,9 +55,9 @@ class Command(BaseCommand): def add_type_product_category(self): for c in tqdm(self.product_type_category_sql(), desc='Add type product category'): - type = ProductType.objects.get(index_name='wine') + type = ProductType.objects.get(index_name=ProductType.WINE) category = TagCategory.objects.get(index_name=c.tag_category) - if type and category not in type.tag_categories.all(): + if category not in type.tag_categories.all(): type.tag_categories.add(category) self.stdout.write(self.style.WARNING(f'Add type product category objects.')) @@ -116,7 +115,7 @@ class Command(BaseCommand): select DISTINCT m.product_id, - lower(trim(CONVERT(m.value USING utf8))) as tag_value, + trim(CONVERT(m.value USING utf8)) as tag_value, trim(CONVERT(v.key_name USING utf8)) as tag_category FROM product_metadata m JOIN product_key_value_metadata v on v.id = m.product_key_value_metadatum_id @@ -133,7 +132,7 @@ class Command(BaseCommand): ) product = Product.objects.get(old_id=t.product_id) for tag in tags: - if product not in tag.products.all(): + if tag not in product.tags.all(): product.tags.add(tag) self.stdout.write(self.style.WARNING(f'Add or get tag objects.')) diff --git a/project/settings/base.py b/project/settings/base.py index fba7f4b4..1772c2c8 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 +ELASTICSEARCH_DSL_AUTOSYNC = False diff --git a/project/settings/local.py b/project/settings/local.py index 959e6149..3d0c9981 100644 --- a/project/settings/local.py +++ b/project/settings/local.py @@ -80,11 +80,11 @@ LOGGING = { 'py.warnings': { 'handlers': ['console'], }, - 'django.db.backends': { - 'handlers': ['console', ], - 'level': 'DEBUG', - 'propagate': False, - }, + # 'django.db.backends': { + # 'handlers': ['console', ], + # 'level': 'DEBUG', + # 'propagate': False, + # }, } }