This commit is contained in:
Виктор Гладких 2019-11-20 15:29:03 +03:00
parent b42b75609a
commit c570cfdadd

View File

@ -1,6 +1,7 @@
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.db import connections from django.db import connections
from establishment.management.commands.add_position import namedtuplefetchall from establishment.management.commands.add_position import namedtuplefetchall
from django.db.models import Q
from tag.models import Tag, TagCategory from tag.models import Tag, TagCategory
from product.models import Product, ProductType from product.models import Product, ProductType
from tqdm import tqdm from tqdm import tqdm
@ -67,8 +68,7 @@ class Command(BaseCommand):
with connections['legacy'].cursor() as cursor: with connections['legacy'].cursor() as cursor:
cursor.execute(''' cursor.execute('''
select select
DISTINCT DISTINCT
m.id as old_id,
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 trim(CONVERT(v.key_name USING utf8)) as tag_category
FROM product_metadata m FROM product_metadata m
@ -103,6 +103,14 @@ class Command(BaseCommand):
p.tags.clear() p.tags.clear()
print('End clear tags product') 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): def product_sql(self):
with connections['legacy'].cursor() as cursor: with connections['legacy'].cursor() as cursor:
cursor.execute(''' cursor.execute('''
@ -145,6 +153,7 @@ class Command(BaseCommand):
def handle(self, *args, **kwargs): def handle(self, *args, **kwargs):
self.remove_tags_product() self.remove_tags_product()
self.remove_tags()
self.add_category_tag() self.add_category_tag()
self.add_type_product_category() self.add_type_product_category()
self.add_tag() self.add_tag()