I have a django application which has two models like this:
class MyModel(models.Model):
name = models.CharField()
country = models.ForeignKey('Country')
class Country(models.Model):
code2 = models.CharField(max_length=2, primary_key=True)
name = models.CharField()
The admin class for MyModel
looks like this:
class MyModelAdmin(admin.ModelAdmin):
list_display = ('name', 'country',)
list_filter = ('country',)
admin.site.register(models.MyModel, MyModelAdmin)
The Country
table contains ~250 countries. Only a handful of countries are actually referenced by some MyModel
instance.
The problem is that the list filter in the django admin lists ALL countries in the filter panel. Listing all countries (and not just those that are referenced by an instance) pretty much defeats the purpose of having the list filter in this case.
Is there some to only display the countries referenced by MyModel
as choices in the list filter? (I use Django 1.3.)