Use custom admin filters in ModelAdmin
ModelAdmin now has a lookup_allowed method which is used to either allow a lookup or raise a SuspiciousOperation exception. By default, lookup_allowed whitelists fields in list_filter or date_hierarchy; adding additional fields may be done by a simple subclass:
class FooAdmin(ModelAdmin):
…
def lookup_allowed(self, lookup):
# Django 1.2.4 restricted the list of allowed lookups to only those
# specified in list_filter or date_hierarchy, which doesn't help when
# we need to filter on a list with thousands of options. We'll
# override that to allow the few which we actually use:
if lookup in ('related__pk', 'related__custom_field'):
return True
return super(FooAdmin, self).lookup_allowed(lookup)
Читайте також:
- Python + CouchDB
- django custom admin
- Retrieving elements in a specific order in django
- How to expire session on browser close in django
- Ordering related objects in Django
- Django suit admin inline pagination
- Django defer, only
- django postgresql та SCHEMA для таблиць
- MemcachedKeyLengthError: Key length is > 250
- Django mongoengine cache backend