For instance:
class Foo(models.Model):
bar = models.OneToOneField(
\'app.Bar\',
limit_choices_to=Q(type=1) & Q(foo=None) | Q(foo=inst
If you pass a callable to limit_choices_to
, that callable has no reference to the current instance. As such, you can't filter based on the current instance either.
There are several other ways to achieve what you want, such as overriding formfield_for_foreignkey()
as you mentioned, or overriding the formfield's queryset in the form's __init__()
method. limit_choices_to
just isn't one of them.