added transfer for product notes
This commit is contained in:
parent
22521f76fc
commit
7064790606
36
apps/product/migrations/0012_auto_20191112_0937.py
Normal file
36
apps/product/migrations/0012_auto_20191112_0937.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# Generated by Django 2.2.7 on 2019-11-12 09:37
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('product', '0011_product_win_import_id'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='product',
|
||||
name='win_import_id',
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ProductNote',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created', models.DateTimeField(default=django.utils.timezone.now, editable=False, verbose_name='Date created')),
|
||||
('modified', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
||||
('text', models.TextField(verbose_name='text')),
|
||||
('product', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='notes', to='product.Product', verbose_name='product')),
|
||||
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='notes', to=settings.AUTH_USER_MODEL, verbose_name='author')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'product notes',
|
||||
'verbose_name_plural': 'product note',
|
||||
},
|
||||
),
|
||||
]
|
||||
|
|
@ -193,9 +193,6 @@ class Product(TranslatedFieldsMixin, BaseAttributes):
|
|||
validators=[MinValueValidator(EARLIEST_VINTAGE_YEAR),
|
||||
MaxValueValidator(LATEST_VINTAGE_YEAR)])
|
||||
gallery = models.ManyToManyField('gallery.Image', through='ProductGallery')
|
||||
win_import_id = models.CharField(max_length=255,
|
||||
blank=True, null=True, default=None,
|
||||
help_text=_('attribute from legacy db'))
|
||||
reviews = generic.GenericRelation(to='review.Review')
|
||||
comments = generic.GenericRelation(to='comment.Comment')
|
||||
awards = generic.GenericRelation(to='main.Award', related_query_name='product')
|
||||
|
|
@ -409,3 +406,26 @@ class ProductClassification(models.Model):
|
|||
"""Meta class."""
|
||||
verbose_name = _('product classification')
|
||||
verbose_name_plural = _('product classifications')
|
||||
|
||||
|
||||
class ProductNoteQuerySet(models.QuerySet):
|
||||
"""QuerySet for model ProductNote."""
|
||||
|
||||
|
||||
class ProductNote(ProjectBaseMixin):
|
||||
"""Note model for Product entity."""
|
||||
text = models.TextField(verbose_name=_('text'))
|
||||
product = models.ForeignKey(Product, on_delete=models.PROTECT,
|
||||
related_name='notes',
|
||||
verbose_name=_('product'))
|
||||
user = models.ForeignKey('account.User', on_delete=models.PROTECT,
|
||||
null=True,
|
||||
related_name='notes',
|
||||
verbose_name=_('author'))
|
||||
|
||||
objects = ProductNoteQuerySet.as_manager()
|
||||
|
||||
class Meta:
|
||||
"""Meta class."""
|
||||
verbose_name_plural = _('product note')
|
||||
verbose_name = _('product notes')
|
||||
|
|
|
|||
|
|
@ -113,18 +113,17 @@ def transfer_product():
|
|||
pprint(f"transfer_product errors: {errors}")
|
||||
|
||||
|
||||
def transfer_product_description():
|
||||
pass
|
||||
# queryset = transfer_models.Products.objects.all()
|
||||
# serialized_data = product_serializers.ProductSerializer(
|
||||
# data=list(queryset.values()),
|
||||
# many=True)
|
||||
# if serialized_data.is_valid():
|
||||
# serialized_data.save()
|
||||
# else:
|
||||
# errors = []
|
||||
# for d in serialized_data.errors: errors.append(d) if d else None
|
||||
# pprint(f"transfer_product errors: {errors}")
|
||||
def transfer_product_note():
|
||||
queryset = transfer_models.ProductNotes.objects.exclude(text='')
|
||||
serialized_data = product_serializers.ProductNoteSerializer(
|
||||
data=list(queryset.values()),
|
||||
many=True)
|
||||
if serialized_data.is_valid():
|
||||
serialized_data.save()
|
||||
else:
|
||||
errors = []
|
||||
for d in serialized_data.errors: errors.append(d) if d else None
|
||||
pprint(f"transfer_product_note errors: {errors}")
|
||||
|
||||
|
||||
def transfer_plate():
|
||||
|
|
@ -166,9 +165,9 @@ data_types = {
|
|||
"product": [
|
||||
transfer_product,
|
||||
],
|
||||
# "product_description": [
|
||||
# transfer_product_description,
|
||||
# ],
|
||||
"product_note": [
|
||||
transfer_product_note,
|
||||
],
|
||||
"souvenir": [
|
||||
transfer_plate,
|
||||
transfer_plate_image,
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class Command(BaseCommand):
|
|||
'inquiries', # №6 - перенос запросов оценок
|
||||
'wine_characteristics',
|
||||
'product',
|
||||
'product_description',
|
||||
'product_note',
|
||||
'souvenir',
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -973,7 +973,7 @@ class Products(MigrateMixin):
|
|||
class ProductNotes(MigrateMixin):
|
||||
using = 'legacy'
|
||||
|
||||
product_id = models.ForeignKey(Products, on_delete=models.DO_NOTHING)
|
||||
product = models.ForeignKey(Products, on_delete=models.DO_NOTHING)
|
||||
text = models.CharField(max_length=255)
|
||||
win_import_id = models.CharField(max_length=255)
|
||||
|
||||
|
|
|
|||
|
|
@ -541,3 +541,27 @@ class PlateImageSerializer(serializers.ModelSerializer):
|
|||
product_qs = models.Product.objects.filter(old_id=product_id)
|
||||
if product_qs.exists():
|
||||
return product_qs.first()
|
||||
|
||||
|
||||
class ProductNoteSerializer(TransferSerializerMixin):
|
||||
product_id = serializers.PrimaryKeyRelatedField(
|
||||
queryset=transfer_models.Products.objects.all())
|
||||
text = serializers.CharField(allow_blank=True)
|
||||
|
||||
class Meta:
|
||||
model = models.ProductNote
|
||||
fields = (
|
||||
'product_id',
|
||||
'text',
|
||||
)
|
||||
|
||||
def validate(self, attrs):
|
||||
attrs['product'] = self.get_product(attrs.pop('product_id'))
|
||||
return attrs
|
||||
|
||||
def get_product(self, product):
|
||||
if product:
|
||||
old_id = product.id if hasattr(product, 'id') else product
|
||||
qs = models.Product.objects.filter(old_id=old_id)
|
||||
if qs.exists():
|
||||
return qs.first()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user