diff --git a/apps/establishment/management/commands/update_employee.py b/apps/establishment/management/commands/update_employee.py index dfe8b5a0..41831f0d 100644 --- a/apps/establishment/management/commands/update_employee.py +++ b/apps/establishment/management/commands/update_employee.py @@ -2,8 +2,7 @@ from django.core.management.base import BaseCommand from django.db import connections from establishment.management.commands.add_position import namedtuplefetchall from establishment.models import Employee -from django.db.models import Q - +from tqdm import tqdm class Command(BaseCommand): help = 'Add employee from old db to new db.' @@ -28,10 +27,7 @@ class Command(BaseCommand): def handle(self, *args, **options): objects = [] - for e in self.employees_sql(): - empl = Employee.objects.filter(old_id=e.profile_id) - if empl.exists(): - empl.name = e.name - empl.save() + for e in tqdm(self.employees_sql()): + empl = Employee.objects.filter(old_id=e.profile_id).update(name=e.name) self.stdout.write(self.style.WARNING(f'Update employee name objects.')) diff --git a/apps/product/management/commands/add_product_tag.py b/apps/product/management/commands/add_product_tag.py index a0f56b71..5633230c 100644 --- a/apps/product/management/commands/add_product_tag.py +++ b/apps/product/management/commands/add_product_tag.py @@ -57,7 +57,7 @@ class Command(BaseCommand): for t in tqdm(self.tag_sql(), desc='Add tags'): category = TagCategory.objects.get(index_name=t.tag_category) - tag = Tag.objects.filter(label={"en-GB": t.tag_value}, + tag = Tag.objects.filter( category=category, value=t.tag_value ) @@ -96,7 +96,21 @@ class Command(BaseCommand): self.stdout.write(self.style.WARNING(f'Add or get tag objects.')) + def check_tag(self): + tags = Tag.objects.filter(value__contains='_').all() + for tag in tqdm(tags, desc='Check label for tag'): + new_label = {} + for k, v in tag.label.items(): + if isinstance(v, str) and '_' in v: + sp = v.split('_') + v = ' '.join([sp[0].capitalize()] + sp[1:]) + new_label[k] = v + tag.label = new_label + tag.save() + + def handle(self, *args, **kwargs): self.add_category_tag() self.add_tag() - self.add_product_tag() \ No newline at end of file + self.add_product_tag() + self.check_tag() \ No newline at end of file