gault-millau/apps/product/management/commands/check_serial_number.py
Виктор Гладких a2087213a4 Check serial number command
2019-11-21 15:22:22 +03:00

23 lines
893 B
Python

from django.core.management.base import BaseCommand
from django.db import connections
from establishment.management.commands.add_position import namedtuplefetchall
from tag.models import Tag, TagCategory
from product.models import Product, ProductType
from tqdm import tqdm
class Command(BaseCommand):
help = '''Check product serial number from old db to new db.
Run after add_product_tag!!!'''
def check_serial_number(self):
category = TagCategory.objects.get(index_name='serial_number')
tags = Tag.objects.filter(category=category, products__isnull=False)
for tag in tqdm(tags, desc='Update serial number for product'):
tag.products.all().update(serial_number=tag.value)
self.stdout.write(self.style.WARNING(f'Check serial number product end.'))
def handle(self, *args, **kwargs):
self.check_serial_number()