Merge branch 'fix/check_tags' into 'develop'

Fix/check tags

See merge request gm/gm-backend!148
This commit is contained in:
d.kuzmenko 2019-12-09 09:08:02 +00:00
commit 6bf40cc793
4 changed files with 43 additions and 3 deletions

View File

@ -7,7 +7,7 @@ from tqdm import tqdm
class Command(BaseCommand):
help = '''Add add product tags networks from old db to new db.
help = '''Add product tags networks from old db to new db.
Run after add_product!!!'''
def category_sql(self):
@ -101,14 +101,12 @@ class Command(BaseCommand):
p.tags.clear()
print('End clear tags product')
def remove_tags(self):
print('Begin delete many tags')
Tag.objects.\
filter(news__isnull=True, establishments__isnull=True).delete()
print('End delete many tags')
def product_sql(self):
with connections['legacy'].cursor() as cursor:
cursor.execute('''

View File

@ -0,0 +1,20 @@
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)
tag.products.clear()
self.stdout.write(self.style.WARNING(f'Check serial number product end.'))
def handle(self, *args, **kwargs):
self.check_serial_number()

View File

@ -0,0 +1,18 @@
# Generated by Django 2.2.7 on 2019-11-21 09:24
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('product', '0018_purchasedproduct'),
]
operations = [
migrations.AddField(
model_name='product',
name='serial_number',
field=models.CharField(default=None, max_length=255, null=True, verbose_name='Serial number'),
),
]

View File

@ -218,6 +218,10 @@ class Product(GalleryModelMixin, TranslatedFieldsMixin, BaseAttributes,
comments = generic.GenericRelation(to='comment.Comment')
awards = generic.GenericRelation(to='main.Award', related_query_name='product')
serial_number = models.CharField(max_length=255,
default=None, null=True,
verbose_name=_('Serial number'))
objects = ProductManager.from_queryset(ProductQuerySet)()
class Meta: