我想要与完全相同的东西django.contrib.contenttypes.generic.GenericForeignKey
, but OneToOne
代替ForeignKey
。我认为一个简单的(尽管有点不优雅)的解决方法是添加unique=True
到有问题的领域,但这很无聊。
Use unique_together
?
的任意组合content_type
场和ID
field 是一个对象的唯一标识符,因此是 1 比 1。
http://docs.djangoproject.com/en/dev/ref/models/options/#unique-together http://docs.djangoproject.com/en/dev/ref/models/options/#unique-together
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)