serializers.py 658 B

1234567891011121314151617181920212223242526272829
  1. from rest_framework import serializers
  2. from .models import Good, Image
  3. from categories.models import Category
  4. class SubCategorySerializer(serializers.ModelSerializer):
  5. class Meta:
  6. model = Category
  7. fields = ['_id','name']
  8. class ImageSerializer(serializers.ModelSerializer):
  9. class Meta:
  10. model = Image
  11. fields = ['_id','url']
  12. class GoodSerializer(serializers.ModelSerializer):
  13. images = ImageSerializer(many=True)
  14. categories = SubCategorySerializer(many=True)
  15. class Meta:
  16. model = Good
  17. fields = ['_id',"name","price","amount","description","images","categories"]
  18. depth = 1