How to correctly use auto_created attribute in django?

天大地大妈咪最大 提交于 2019-12-04 03:23:26

As far as I am aware, the auto_created attribute in the Meta class is undocumented, so you should avoid using it.

As the AttributeError says, it is not possible to use add() for a many to many field that uses an intermediary model. The correct fix is to create an instance of the intermediate model, instead of using add().

class3.objects.create(field_1=c1, field_2=c2, field_3=1).

See the docs on extra fields in many to many relationships for more info.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!