Fix for merge

This commit is contained in:
Виктор Гладких 2019-11-12 18:37:43 +03:00
parent 01d6403ad3
commit 89fa7c5d56
2 changed files with 19 additions and 9 deletions

View File

@ -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.'))

View File

@ -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()
self.add_product_tag()
self.check_tag()