Hello everyone,
I've recently started learning and (developing with) the Django REST framework. I tried to use the "nested relationship" within my model and got a "non_field_errors" in the browsable API web view. Then I tried the simple album+tracks example from the documentation, which got the same error.
models.py
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')
order = models.IntegerField()
title = models.CharField(max_length=100)
duration = models.IntegerField()
class Meta:
unique_together = ('album', 'order')
order_by = 'order'
def __unicode__(self):
return '%d: %s' % (self.order, self.title)
serializers.py
class TrackSerializer(serializers.ModelSerializer):
class Meta:
model = Track
fields = ('order', 'title')
class AlbumSerializer(serializers.ModelSerializer):
tracks = TrackSerializer(many=True)
class Meta:
model = Album
fields = ('album_name', 'artist', 'tracks')
ERROR (at http://.../api/albums):Clicking the OPTIONS button reveals the actual correct data structure:
The raw data input of the browsable browser view shows:
{
"album_name": "",
"artist": "",
"tracks": null
}
Posting some raw-data actually works. But it'd be nicer if the web interface would work as well. Especially since I'm wondering if there's something wrong anyway. (even though it seems to work)
Thank you in advance! :)
Regards,
Sebastian