File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,9 @@ def set_property_from_data(
6060 set_property_from_data (field , key , key_value )
6161 else :
6262 set_property_from_data (field , field .name , value )
63+ elif hasattr (field , "related_val" ):
64+ # Use `related_val` to check for many-to-many
65+ field .set (value )
6366 else :
6467 type_hints = get_type_hints (component_or_field )
6568 type_hint = type_hints .get (name )
Original file line number Diff line number Diff line change @@ -163,3 +163,12 @@ def test_set_property_from_data_all_querysets():
163163 component_queryset_field_asserts (component , "queryset_with_none" )
164164 component_queryset_field_asserts (component , "queryset_with_empty_queryset" )
165165 component_queryset_field_asserts (component , "queryset_with_no_typehint" )
166+
167+
168+ @pytest .mark .django_db
169+ def test_set_property_from_data_many_to_many ():
170+ component = FakeComponent (component_name = "test" , component_id = "12345678" )
171+ component .model .pk = 1
172+
173+ # No `TypeError: Direct assignment to the reverse side of a many-to-many set is prohibited.` error gets raised
174+ set_property_from_data (component .model , "taste_set" , [])
You can’t perform that action at this time.
0 commit comments