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)
Читайте також:
- Django admin filter by ranges of ages
- Django admin filter by ranges of dates with calendar
- Ordering related objects in Django
- How to expire session on browser close in django
- Django yandex and google maps integration
- django postgresql та SCHEMA для таблиць
- django-mptt деревоподібний select
- Проксі моделі Django
- Retrieving elements in a specific order in django
- Fix Django 1.4 admin_site ForeignKeyRawIdWidget issue