1👍
✅
You can limit foreign key choices with limit_choices_to
:
class SomeClass(models.Model):
def __unicode__(self):
return unicode(self.name)
boolean = models.BooleanField(default=1)
name = models.CharField(max_length=64, unique=True)
class SomeClass2(models.Model):
def __unicode__(self):
return unicode(self.name)
child_item = models.ForeignKey(SomeClass, to_field='name',
limit_choices_to={'boolean': True})
Source:stackexchange.com