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

20 lines
733 B
Python

from django.core.management.base import BaseCommand
from tag.models import Tag, TagCategory
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()