1👍
You defined your trackSerializer
in wrong way.
Track
model doesn’t have track_parent
or track_child
attributes. They belong to Album
model. Remember that related_name
is an attribute to defined how your pointed model, in this case Album
may retrieve their backwards model instances aka Track
instances. related_name
does not rename the attribute as you think it does.
Also, track_parent
represents Track
instances, you can’t serializer a Track
instance using albumSerializer
class trackSerializer(serializers.ModelSerializer):
class Meta:
model = Track
fields = ('pk_track',)
class albumSerializer(serializers.ModelSerializer):
album_title = masterSerializer()
album_description = masterSerializer()
track_parent = trackSerializer(many=True, read_only=True)
track_child = trackSerializer(many=True, read_only=True)
class Meta:
model = Album
fields = ('album_title', 'album_description','track_parent', 'track_child')
👤levi
Source:stackexchange.com