some parts of product - fix custom pagination - add id to pages list
This commit is contained in:
27
apps/product/web/api/v1/serializers.py
Normal file
27
apps/product/web/api/v1/serializers.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from rest_framework import serializers
|
||||
from apps.product import models as product_models
|
||||
|
||||
|
||||
class ReferenceProductSerializer(serializers.ModelSerializer):
|
||||
""" Serializer of reference product """
|
||||
|
||||
class Meta:
|
||||
model = product_models.ReferenceProduct
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class ProductSerializer(serializers.ModelSerializer):
|
||||
""" Serializer of product """
|
||||
|
||||
class Meta:
|
||||
model = product_models.Product
|
||||
fields = '__all__'
|
||||
|
||||
def to_representation(self, instance):
|
||||
""" Custom output of product serializer """
|
||||
|
||||
representation = super().to_representation(instance)
|
||||
if instance.reference:
|
||||
representation['reference'] = ReferenceProductSerializer(instance.reference).data
|
||||
|
||||
return representation
|
||||
Reference in New Issue
Block a user