[Django]-Django API Framework – Nested Models View

0👍

install drf-writable-nested https://pypi.org/project/drf-writable-nested/

from rest_framework import serializers
from drf_writable_nested.serializers import WritableNestedModelSerializer
   

class ShopSerializer(serializers.ModelSerializer):
    class Meta:
        model = Shop
        fields = [  
            'name',
            'address'
        ]

class ProductSerializer(WritableNestedModelSerializer):
    shop = ShopSerializer()
    class Meta:
        model = Product
        fields = [
            'pk',
            'shop'
            'name'
            'price'
            ]

        
      
👤AdR

Leave a comment