fixed transfer product with sub type plates
This commit is contained in:
parent
3a1f57e195
commit
0610075706
|
|
@ -4,6 +4,7 @@ from rest_framework import serializers
|
||||||
from tag import models as tag_models
|
from tag import models as tag_models
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from product.models import ProductType, ProductSubType
|
from product.models import ProductType, ProductSubType
|
||||||
|
from django.utils.text import slugify
|
||||||
|
|
||||||
|
|
||||||
class SecondDbManager(models.Manager):
|
class SecondDbManager(models.Manager):
|
||||||
|
|
@ -90,3 +91,6 @@ class TransferSerializerMixin(serializers.ModelSerializer):
|
||||||
index_name__icontains=product_sub_type)
|
index_name__icontains=product_sub_type)
|
||||||
if qs.exists():
|
if qs.exists():
|
||||||
return qs.first()
|
return qs.first()
|
||||||
|
|
||||||
|
def get_slug(self, name, old_id):
|
||||||
|
return slugify(f'{name}-{old_id}')
|
||||||
|
|
@ -433,9 +433,6 @@ class ProductSerializer(TransferSerializerMixin):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_slug(self, name, old_id):
|
|
||||||
return slugify(f'{name}-{old_id}')
|
|
||||||
|
|
||||||
|
|
||||||
class PlateSerializer(TransferSerializerMixin):
|
class PlateSerializer(TransferSerializerMixin):
|
||||||
|
|
||||||
|
|
@ -454,14 +451,17 @@ class PlateSerializer(TransferSerializerMixin):
|
||||||
)
|
)
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
|
old_id = attrs.pop('id')
|
||||||
|
name = attrs.get('name')
|
||||||
product_type = self.get_product_type(self.PRODUCT_TYPE_INDEX_NAME)
|
product_type = self.get_product_type(self.PRODUCT_TYPE_INDEX_NAME)
|
||||||
|
|
||||||
attrs['old_id'] = attrs.pop('id')
|
attrs['old_id'] = old_id
|
||||||
attrs['vintage'] = self.get_vintage_year(attrs.pop('vintage'))
|
attrs['vintage'] = self.get_vintage_year(attrs.pop('vintage'))
|
||||||
attrs['product_type'] = product_type
|
attrs['product_type'] = product_type
|
||||||
attrs['state'] = self.Meta.model.PUBLISHED
|
attrs['state'] = self.Meta.model.PUBLISHED
|
||||||
attrs['subtype'] = self.get_product_sub_type(product_type,
|
attrs['subtype'] = self.get_product_sub_type(product_type,
|
||||||
self.PRODUCT_SUB_TYPE_INDEX_NAME)
|
self.PRODUCT_SUB_TYPE_INDEX_NAME)
|
||||||
|
attrs['slug'] = self.get_slug(name, old_id)
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user