OK, first, you're using the old docs. DRF has long been version 3 and those docs are v2.x. The correct location is http://www.django-rest-framework.org/api-guide/relations/
Secondly, follow the example of how AlbumSerializer includes TrackSerializer, and do the same in TrackSerializer. On Wednesday, March 14, 2018 at 11:14:49 AM UTC-4, Leif wrote: > > Dear Django, > > I have a question about django rest framework relations. I am looking at > the example in > http://www.tomchristie.com/rest-framework-2-docs/api-guide/relations. In > my situation there is additional class called Xyz: > > class Xyz(models.Model): > xyz_name = models.CharField(max_length=100) > name2 = models.CharField(max_length=100) > > class Album(models.Model): > album_name = models.CharField(max_length=100) > artist = models.CharField(max_length=100) > > class Track(models.Model): > album = models.ForeignKey(Album, related_name='tracks') > xyz = models.ForeignKey(Xyz, related_name=‘xyz’) > order = models.IntegerField() > title = models.CharField(max_length=100) > duration = models.IntegerField() > > here is the example of serializer in the link above. > > class TrackSerializer(serializers.ModelSerializer): > class Meta: > model = Track > fields = ('order', 'title') > > class AlbumSerializer(serializers.ModelSerializer): > tracks = TrackSerializer(many=True, read_only=True) > > class Meta: > model = Album > fields = ('album_name', 'artist', 'tracks') > > My question is how to include XyzSerializer(serializers.ModelSerializer) > so all three objects will be included in json output. > > Thank you very much in advance, > > Leif > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/913fd4e1-28d5-47b9-b9c1-ae65db7854fe%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.