mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-12-01 22:14:06 +03:00
Fix object creation with reverse M2M when related_name unspecified
It seems that field.related_query_name() does not return the related_name for reverse M2M relations when related_name is not explicitly set in the M2M field definition. So, change to use obj.get_accessor_name(), where obj is an instance of RelatedObject, as are returned by a model's _meta.get_all_related_many_to_many_objects(), or as in the tuples returned by _meta.get_all_m2m_objects_with_model().
This commit is contained in:
parent
97430c0d9c
commit
b7b57adee2
|
@ -873,7 +873,7 @@ class ModelSerializer(Serializer):
|
||||||
|
|
||||||
# Reverse m2m relations
|
# Reverse m2m relations
|
||||||
for (obj, model) in meta.get_all_related_m2m_objects_with_model():
|
for (obj, model) in meta.get_all_related_m2m_objects_with_model():
|
||||||
field_name = obj.field.related_query_name()
|
field_name = obj.get_accessor_name()
|
||||||
if field_name in attrs:
|
if field_name in attrs:
|
||||||
m2m_data[field_name] = attrs.pop(field_name)
|
m2m_data[field_name] = attrs.pop(field_name)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user