In Django 1.11, I have 2 models, Foo
and Bar
:
class Foo(models.Model):
name = models.CharField()
extra = models.BooleanField(default=False)
class Bar(models.Model):
name = models.CharField()
extra_foo = models.ForeignKey(Foo)
My admin.py
looks like this:
class BarInline(admin.StackedInline):
model = Bar
fields = ('name', 'extra_foo')
class FooAdmin(admin.ModelAdmin):
fields('name')
inlines = [BarInline]
My problem is that the in the Bar inline form, the dropdown for extra_foo
shows all of my existing Foo
s. I want it to only show Foo
s for which extra
is true
. How can I modify the admin to restrict the available options in a select box to a subset of the whole?