django Cannot set values on a ManyToManyField which specifies an intermediary model. Use Manager instead

前端 未结 5 923
长情又很酷
长情又很酷 2020-12-03 07:28

i am working on saving on the same form two tables - having a m2m relation. I don\'t succeed, my error persists with something like: Cannot set values on a ManyToManyField w

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 08:07

    As of the Django 2.2 release you can also specify a through_defaults on the field in order to use add, create and assignment:

    The RelatedManager.add(), create(), remove(), set(), get_or_create(), and update_or_create() methods are now allowed on many-to-many relationships with intermediate models. The new through_defaults argument is used to specify values for new intermediate model instance(s).

    In your case since all the fields already have defaults it might just work in 2.2.

提交回复
热议问题