0👍
✅
CarSerializer.route
declaration is wrong. It must be an instance of RouteSerializer
, like this:
class CarSerializer(serializers.ModelSerializer):
route = RouteSerializer(read_only=True)
class Meta:
model = Car
fields = ("id", "name", "route")
This is called “nested relationship”, see docs at https://www.django-rest-framework.org/api-guide/relations/#nested-relationships
Source:stackexchange.com