1๐
โ
I think what you need is Nested Relationships. For that you would need to write a new serializer for Item
model and include it in the MyUserSerializer
:
class MyUserSerializer(serializers.HyperlinkedModelSerializer):
items = serializers.ItemSerializer(many=True)
class Meta:
model = MyUser
fields = (...., 'items', ...)
class ItemSerializer(serializers.ModelSerializer):
....
class Meta:
model = Item
fields = (....) # your fields
If you also need the url
for items just as in MyUserSerializer
, you can extend the other ItemSerializer
with HyperlinkedModelSerializer
.
๐คAKS
Source:stackexchange.com