I want to add a custom model method to the admin filter, however it fails.
Example Foo:
class Foo(models.Model):
number = models.IntegerField()
def big_enough(self):
return self.number > 99
now at the admin panel:
class FooAdmin(admin.ModelAdmin):
list_filter = ('number', 'big_enough')
Fails, I get the error
ImproperlyConfigured at /admin/test/foo/ 'FooAdmin.list_filter[0]' refers to field 'big_enough' that is missing from model 'Foo'.
Django allows the user of the admin site to filter the instances of a Model by adding the list_filter attribute to your ModelAdmin objects. You can find more information about the Django's filtering utilities in the official documentation, in the Django Admin Site section.
Admin Taxonomy Filter helps you to filter posts or custom post types in the admin area (the post list table) by custom taxonomies. It's similar to filter posts by categories, which is supported by default.
To login to the site, open the /admin URL (e.g. http://127.0.0.1:8000/admin ) and enter your new superuser userid and password credentials (you'll be redirected to the login page, and then back to the /admin URL after you've entered your details).
See this SO thread. It's not as easy as it feels like it should be.
You cannot use a model method for this purpose. list_filter
is used to filter a django queryset, which cannot meaningfully utilize bare functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With