django rest framework model serializers - read nested, write flat

后端 未结 3 1101
忘了有多久
忘了有多久 2021-02-12 20:38

I have a situation where my client is attempting to write a representation that includes a list of fk\'s

{
languages: [1]
last_name: \"Beecher\"
settings: 1
stat         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-12 21:01

    The simplest thing that occurs to me is to override get_serializer_class() on your view for POST/PUT to return a modified serializer not specifying the depth parameter and using a PrimaryKeyRelatedField for your languages field.

提交回复
热议问题