python - Django REST framework: nested relationship: non_field_errors -


In a Django-REST-framework project I tried to use a nested relationship and browsable API "non_field_errors "Found" : ALBUM_NAME = models.CharField (MAX_LENGTH = 100) artist = models.CharField (MAX_LENGTH = 100) class track from the imported model class album (models.Model) >

serializers.py:

  from myapp.models import album from rest_framework import serializers, track square TrackSeriali track zer (serializers.ModelSerializer): class meta model = track regions = ('command', 'title ') Class AlbumSerializer (serializers.ModelSerializer): tracks = TrackSerializer (many = true) square meta model = album areas = (The 'track input field' has been red marked with error / error message:  

error (but ../ album):

non_field_errors

Click on the Option button to reveal the real & true data structure.

Their appropriate propertie

Browse the browsable browser to see the raw data input With nest tracks

posting some valid raw data

  {"album_name": "", "artist": "", "track": null }  actually works But it would be nice if the web interface form will also work. Especially since I am thinking that something strange is happening anyway. 

Thank you in advance!

I have also experienced this problem one way to get rid of this error is to use Category: AlbumSerializer (serializers.ModelSerializer): tracks = serializers.RelatedField (many = true) class meta models = album areas = ('

though , It removes nested track fields and displays only a string representation of the tracks.

EDIT: I understood that this is what you want:

  class albumSerializer (serializers.ModelSerializer): class meta model = album areas = ('ALBUM_NAME', 'artist', 'tracks') read_only_fields = ('tracks',) depth = 1  < / Pre> 

This UI will be caused by the nest without throwing the error.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -