#DRF sub serializer POST

4 messages · Page 1 of 1 (latest)

fiery hazel
#

I have two models, A and B, A with a foreign to B
If I create a Django Rest Framework serializer for A with relatedField to B so that when I create a model from json:

{
"B": {},
"a_attribute_1": 123,
}

both A and B are created?

#

is this functionality default for ModelSerializers?

tidal token
#

No, default DRF modelserializer will ask you to manually handle create/update of related fields

#

however there is a library for that drf-creatable-nested if you want a easier solution