mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-31 10:30:01 +03:00
fixes #6751
This commit is contained in:
parent
72de94a05d
commit
9942453e31
|
@ -973,12 +973,17 @@ class ModelSerializer(Serializer):
|
||||||
# Note that unlike `.create()` we don't need to treat many-to-many
|
# Note that unlike `.create()` we don't need to treat many-to-many
|
||||||
# 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 = []
|
||||||
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 not in info.relations or not info.relations[attr].to_many:
|
||||||
field = getattr(instance, attr)
|
|
||||||
field.set(value)
|
|
||||||
else:
|
|
||||||
setattr(instance, attr, value)
|
setattr(instance, attr, value)
|
||||||
|
else:
|
||||||
|
m2m_fields.append((attr, value))
|
||||||
|
|
||||||
|
for attr, value in m2m_fields:
|
||||||
|
field = getattr(instance, attr)
|
||||||
|
field.set(value)
|
||||||
|
|
||||||
instance.save()
|
instance.save()
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|
Loading…
Reference in New Issue
Block a user