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)
Читайте також:
- мультимовність djnago
- django-stdimage traceback "The '%s' attribute has no file associated with it"
- Django yandex and google maps integration
- Retrieving elements in a specific order in django
- Fix Django 1.4 admin_site ForeignKeyRawIdWidget issue
- Ordering related objects in Django
- django postgresql та SCHEMA для таблиць
- Django defer, only
- Django admin filter by ranges of dates with calendar
- django custom admin