mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 08:29:59 +03:00
STRICT_PARTIAL_UPDATE=True enforce partial
using a new configuration flag to decide if to enforce a partial update
This commit is contained in:
parent
cdc956a96c
commit
f555c79724
|
@ -997,13 +997,18 @@ class ModelSerializer(Serializer):
|
||||||
# relationships as being a special case. During updates we already
|
# relationships as being a special case. During updates we already
|
||||||
# have an instance pk for the relationships to be associated with.
|
# have an instance pk for the relationships to be associated with.
|
||||||
m2m_fields = []
|
m2m_fields = []
|
||||||
|
update_fields = []
|
||||||
for attr, value in validated_data.items():
|
for attr, value in validated_data.items():
|
||||||
if attr in info.relations and info.relations[attr].to_many:
|
if attr in info.relations and info.relations[attr].to_many:
|
||||||
m2m_fields.append((attr, value))
|
m2m_fields.append((attr, value))
|
||||||
else:
|
else:
|
||||||
setattr(instance, attr, value)
|
setattr(instance, attr, value)
|
||||||
|
update_fields.append(attr)
|
||||||
|
|
||||||
instance.save()
|
if self.partial and api_settings.STRICT_PARTIAL_UPDATE:
|
||||||
|
instance.save(update_fields=update_fields)
|
||||||
|
else:
|
||||||
|
instance.save()
|
||||||
|
|
||||||
# Note that many-to-many fields are set after updating instance.
|
# Note that many-to-many fields are set after updating instance.
|
||||||
# Setting m2m fields triggers signals which could potentially change
|
# Setting m2m fields triggers signals which could potentially change
|
||||||
|
|
Loading…
Reference in New Issue
Block a user