Product type tags
This commit is contained in:
parent
c9a0fb6656
commit
39a406cbc1
|
|
@ -2,7 +2,7 @@ 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 tag.models import Tag, TagCategory
|
from tag.models import Tag, TagCategory
|
||||||
from product.models import Product
|
from product.models import Product, ProductType
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -40,6 +40,29 @@ class Command(BaseCommand):
|
||||||
TagCategory.objects.bulk_create(objects)
|
TagCategory.objects.bulk_create(objects)
|
||||||
self.stdout.write(self.style.WARNING(f'Add or get tag category 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('''
|
||||||
|
select
|
||||||
|
DISTINCT
|
||||||
|
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
|
||||||
|
join products p on p.id = m.product_id
|
||||||
|
where UPPER(trim(p.type)) = 'WINE'
|
||||||
|
''')
|
||||||
|
return namedtuplefetchall(cursor)
|
||||||
|
|
||||||
|
def add_type_product_category(self):
|
||||||
|
for c in tqdm(self.product_type_category_sql(), desc='Add type product category'):
|
||||||
|
types = ProductType.objects.filter(index_name='wine')
|
||||||
|
category = TagCategory.objects.get(index_name=c.tag_category)
|
||||||
|
if types.exists() and category not in types.tag_categories.all():
|
||||||
|
types.tag_categories.add(category)
|
||||||
|
|
||||||
|
self.stdout.write(self.style.WARNING(f'Add type product category objects.'))
|
||||||
|
|
||||||
def tag_sql(self):
|
def tag_sql(self):
|
||||||
with connections['legacy'].cursor() as cursor:
|
with connections['legacy'].cursor() as cursor:
|
||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
|
|
@ -122,6 +145,7 @@ class Command(BaseCommand):
|
||||||
def handle(self, *args, **kwargs):
|
def handle(self, *args, **kwargs):
|
||||||
self.remove_tags_product()
|
self.remove_tags_product()
|
||||||
self.add_category_tag()
|
self.add_category_tag()
|
||||||
|
self.add_type_product_category()
|
||||||
self.add_tag()
|
self.add_tag()
|
||||||
self.check_tag()
|
self.check_tag()
|
||||||
self.add_product_tag()
|
self.add_product_tag()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user