Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何让一个领域依赖于另一个领域?例如
class Example(models.Model): question = models.BooleanField()
那么如果问题是真的:
example1 = models.ForeignKey('Object1')
假时:
example2 = models.ForeignKey('Object2')
或类似的东西?感谢帮助。
我的建议是使用允许多态类型的通用外键。这避免了额外的列。