Merge branch 'fix/check_tags' into 'develop'
Fix/check tags See merge request gm/gm-backend!148
This commit is contained in:
commit
6bf40cc793
|
|
@ -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('''
|
||||
|
|
|
|||
20
apps/product/management/commands/check_serial_number.py
Normal file
20
apps/product/management/commands/check_serial_number.py
Normal 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()
|
||||
18
apps/product/migrations/0019_product_serial_number.py
Normal file
18
apps/product/migrations/0019_product_serial_number.py
Normal 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'),
|
||||
),
|
||||
]
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user