mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 17:09:59 +03:00
Notify about the fields that changed
This allows signal receivers to know specifically what has been changed on the model.
This commit is contained in:
parent
ab40b80fa6
commit
a06043a0ce
|
@ -979,13 +979,16 @@ class ModelSerializer(Serializer):
|
|||
# relationships as being a special case. During updates we already
|
||||
# have an instance pk for the relationships to be associated with.
|
||||
m2m_fields = []
|
||||
changed_fields = []
|
||||
for attr, value in validated_data.items():
|
||||
if attr in info.relations and info.relations[attr].to_many:
|
||||
m2m_fields.append((attr, value))
|
||||
else:
|
||||
setattr(instance, attr, value)
|
||||
if getattr(instance, attr, None) != value:
|
||||
setattr(instance, attr, value)
|
||||
changed_fields.append(attr)
|
||||
|
||||
instance.save()
|
||||
instance.save(update_fields=changed_fields)
|
||||
|
||||
# Note that many-to-many fields are set after updating instance.
|
||||
# Setting m2m fields triggers signals which could potentially change
|
||||
|
|
Loading…
Reference in New Issue
Block a user