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.
My suggestion would be to use a Generic Foreign Key which allows for polymorphic types. This avoids the extra column.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.