user2225970
user2225970

Reputation:

How to make one field dependable of another field in models? Django

How to make one field dependable on another? for example

class Example(models.Model):
    question = models.BooleanField()

then if question is True:

    example1 = models.ForeignKey('Object1')

when false:

    example2 = models.ForeignKey('Object2')

or something like that? Thanks for help.

Upvotes: 0

Views: 158

Answers (1)

crearc
crearc

Reputation: 43

My suggestion would be to use a Generic Foreign Key which allows for polymorphic types. This avoids the extra column.

Upvotes: 1

Related Questions