mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-04-25 19:43:47 +03:00
If null or blank - don't save the nested object
This commit is contained in:
parent
901d2b0eb8
commit
ff1efcf60f
|
@ -891,7 +891,8 @@ class ModelSerializer(Serializer):
|
||||||
# Nested relationships need to be saved before we can save the
|
# Nested relationships need to be saved before we can save the
|
||||||
# parent instance.
|
# parent instance.
|
||||||
for field_name, sub_object in obj._nested_forward_relations.items():
|
for field_name, sub_object in obj._nested_forward_relations.items():
|
||||||
self.save_object(sub_object)
|
if sub_object:
|
||||||
|
self.save_object(sub_object)
|
||||||
setattr(obj, field_name, sub_object)
|
setattr(obj, field_name, sub_object)
|
||||||
|
|
||||||
obj.save(**kwargs)
|
obj.save(**kwargs)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user