With a custom through model for an M2M relationship, .add()
, .create()
and .remove()
are disabled.
通过M2M关系的自定义直通模型,禁用.add(),. create()和.remove()。
At the moment, I attempt to use .add()
(or whatever) and catch and deal with AttributeError
for those custom M2M relationships.
目前,我尝试使用.add()(或其他)并捕获并处理那些自定义M2M关系的AttributeError。
Is there an 'official' way to identify a custom through model, using the Meta
API or otherwise? At this stage in my processing I would rather treat all custom through relationships as generically as possible (rather than lots of if m2m_field.related.through == FooBar
statements)
是否存在使用Meta API或其他方式识别自定义模型的“官方”方式?在我处理的这个阶段,我宁愿尽可能一般地通过关系处理所有自定义(而不是很多,如果m2m_field.related.through == FooBar语句)
(Django 1.8, but if there's a solution for a later version we will be upgrading before long.)
(Django 1.8,但如果有更新版本的解决方案,我们将很快升级。)
1 个解决方案
#1
0
Looks as though
看起来好像
m2m_field.related.through._meta.auto_created is False
does the job.
做的工作。
#1
0
Looks as though
看起来好像
m2m_field.related.through._meta.auto_created is False
does the job.
做的工作。