Check serial number for product

This commit is contained in:
Виктор Гладких 2019-11-21 13:13:19 +03:00
parent 98468f2604
commit 1687e80492
3 changed files with 33 additions and 0 deletions

View File

@ -149,6 +149,17 @@ class Command(BaseCommand):
tag.label = new_label
tag.save()
def check_serail_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.remove_tags_product()
self.remove_tags()

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

@ -219,6 +219,10 @@ class Product(GalleryModelMixin, TranslatedFieldsMixin, BaseAttributes, HasTagsM
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: