tickets: 8851
This data as json
id | created | changetime | last_pulled_from_trac | stage | status | component | type | severity | version | resolution | summary | description | owner | reporter | keywords | easy | has_patch | needs_better_patch | needs_tests | needs_docs | ui_ux |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
8851 | 2008-09-03 18:18:29 | 2020-04-16 12:25:02 | 2022-03-06 03:43:19.949116 | Accepted | new | contrib.admin | New feature | Normal | dev | Add a default option to list_filter in the admin interface | There should be a way to set a default list_filter in the admin interface. For example, if I had a model like this: {{{ #!python DECOM_CHOICES = ( ('N', 'No'), ('Y', 'Yes'), ) class Host(models.Model): hostname = models.CharField(max_length=36, unique=True) decommissioned = models.CharField(max_length=1, choices=DECOM_CHOICES, default='N') ip_address = models.IPAddressField() def __unicode__(self): return self.hostname class HostAdmin(admin.ModelAdmin): fieldsets = [ ('Host Info', {'fields': ['hostname','decommissioned','ip_address']}), list_display = ('hostname', 'ip_address', 'decommissioned') list_filter = ('decommissioned') admin.site.register(Host, HostAdmin) }}} I might want to make it so that by default only hosts that are not marked as decommissioned are displayed by default in the index. It would be nice if I could just pass an option to list_filter to set the a filter that is enabled by default. Perhaps something like this: {{{ #!python list_filter = ('decommissioned__exact=N') # Matches the URL if you click on "No" in the filter list }}} ...or perhaps... {{{ #!python list_filter = ('decommissioned__default') # Have it choose the same default as specified in the model. }}} If there's already a simple way to do this I haven't found it and would appreciate an example. Thanks! | hvdklauw | Riskable <riskable@youknowwhat.com> | admin, list_filter, default | 0 | 0 | 0 | 0 | 0 | 0 |