Django的CreateView动态字段形式与ManyToMany模型通过

问题描述:

我有几个ManyToManyFields模型都使用通过(自定义中间表),我想创建使用CreateView。问题是我没有能力为中间表创建数据。Django的CreateView动态字段形式与ManyToMany模型通过

也可以创建一个intermedicate表项directy,然后ü可以将它添加到多对多的领域,例如

modelObject = YourModel.objects.create(.....) 
intermedicateObject = IntermediateModel.objects.create(.....) 
modelObject.M2MfieldName.add(intermedicateObject)