The code
I have these models :
class Activity(models.Model):
is_child_friendly = models.BooleanField()
free_wifi = models.BooleanField()
parking_avilable = models.BooleanField()
class RouteOrdering(models.Model):
route_id = models.ForeignKey(Route, on_delete=models.CASCADE)
activity_id = models.ForeignKey(Activity, on_delete=models.CASCADE, related_name='tracks')
day = models.IntegerField()
order = models.IntegerField()
class Meta:
ordering = ['order']
And these Serializers:
class ActivitySerializer(serializers.ModelSerializer):
class Meta:
model = Activity
class RouteOrderingSerializer(serializers.ModelSerializer):
class Meta:
model = RouteOrdering
fields = ('id','day','order','route_id','activity_id','tracks')
The problem
I want the RouteOrderingSerializer to return also the activity with the same activity_id. For this I thought I should use nested serializers.
What I've tried
I've tried adding a nested serializer like so:
activity = ActivitySerializer( read_only=True)
But this resulted no output in the endpoint. I know this is not the use case presented in the documentation, and this is probably why its noy working.
Ill be glad to see what code will work to get this done :)