Add category tag for products
This commit is contained in:
parent
9d208610df
commit
7d9b6d1f30
|
|
@ -1,6 +1,5 @@
|
||||||
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 django.db.models import Q
|
|
||||||
from social_django.models import UserSocialAuth
|
from social_django.models import UserSocialAuth
|
||||||
from establishment.management.commands.add_position import namedtuplefetchall
|
from establishment.management.commands.add_position import namedtuplefetchall
|
||||||
from account.models import User
|
from account.models import User
|
||||||
|
|
|
||||||
38
apps/product/management/commands/add_product_tag.py
Normal file
38
apps/product/management/commands/add_product_tag.py
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from django.db import connections
|
||||||
|
from social_django.models import UserSocialAuth
|
||||||
|
from establishment.management.commands.add_position import namedtuplefetchall
|
||||||
|
from account.models import User
|
||||||
|
from tag.models import Tag, TagCategory
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = '''Add add product tags networks from old db to new db.
|
||||||
|
Run after add_product!!!'''
|
||||||
|
|
||||||
|
def category_sql(self):
|
||||||
|
with connections['legacy'].cursor() as cursor:
|
||||||
|
cursor.execute('''
|
||||||
|
select DISTINCT
|
||||||
|
id,
|
||||||
|
key_name as category,
|
||||||
|
value_type as value_type
|
||||||
|
from product_key_value_metadata
|
||||||
|
''')
|
||||||
|
return namedtuplefetchall(cursor)
|
||||||
|
|
||||||
|
def add_category_tag(self):
|
||||||
|
objects = []
|
||||||
|
for c in tqdm(self.category_sql()):
|
||||||
|
cat = TagCategory.objects.filter(index_name=c.category,
|
||||||
|
value_type=c.value_type,
|
||||||
|
label={'en-GB':c.category})
|
||||||
|
if not cat.exists():
|
||||||
|
objects.append(TagCategory(index_name=c.category,
|
||||||
|
value_type=c.value_type,
|
||||||
|
label={'en-GB': c.category}))
|
||||||
|
TagCategory.objects.bulk_create(objects)
|
||||||
|
self.stdout.write(self.style.WARNING(f'Created tag category.'))
|
||||||
|
|
||||||
|
def handle(self, *args, **kwargs):
|
||||||
|
self.add_category_tag()
|
||||||
|
|
@ -107,11 +107,13 @@ class TagCategory(TranslatedFieldsMixin, models.Model):
|
||||||
STRING = 'string'
|
STRING = 'string'
|
||||||
LIST = 'list'
|
LIST = 'list'
|
||||||
INTEGER = 'integer'
|
INTEGER = 'integer'
|
||||||
|
FLOAT = 'float'
|
||||||
|
|
||||||
VALUE_TYPE_CHOICES = (
|
VALUE_TYPE_CHOICES = (
|
||||||
(STRING, _('string')),
|
(STRING, _('string')),
|
||||||
(LIST, _('list')),
|
(LIST, _('list')),
|
||||||
(INTEGER, _('integer')),
|
(INTEGER, _('integer')),
|
||||||
|
(FLOAT, _('float'))
|
||||||
)
|
)
|
||||||
|
|
||||||
label = TJSONField(blank=True, null=True, default=None,
|
label = TJSONField(blank=True, null=True, default=None,
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ pycountry==19.8.18
|
||||||
django-phonenumber-field[phonenumbers]==2.1.0
|
django-phonenumber-field[phonenumbers]==2.1.0
|
||||||
django-timezone-field==3.1
|
django-timezone-field==3.1
|
||||||
|
|
||||||
|
# custom
|
||||||
|
tqdm==4.38.0
|
||||||
|
|
||||||
# auth socials
|
# auth socials
|
||||||
django-rest-framework-social-oauth2==1.1.0
|
django-rest-framework-social-oauth2==1.1.0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user