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/fecb9167-cfa1-49e6-8af4-7f3b56860f23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to