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)

coded by nessus