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()
次に、質問が True の場合:
example1 = models.ForeignKey('Object1')
false の場合:
example2 = models.ForeignKey('Object2')
またはそのようなもの?手伝ってくれてありがとう。
私の提案は、多相型を可能にする汎用外部キーを使用することです。これにより、余分な列が回避されます。