Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andybak/974149 to your computer and use it in GitHub Desktop.
Save andybak/974149 to your computer and use it in GitHub Desktop.

Revisions

  1. @acdha acdha renamed this gist Feb 10, 2011. 1 changed file with 4 additions and 3 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,12 @@
    class FooAdmin(ModelAdmin):
    def lookup_allowed(self, lookup):
    def lookup_allowed(self, key, value):
    # NOTE: Django 1.2.5 changed the call signature to add the value
    # 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'):
    if key in ('related__pk', 'related__custom_field'):
    return True

    return super(FooAdmin, self).lookup_allowed(lookup)
    return super(FooAdmin, self).lookup_allowed(key, value)
  2. @acdha acdha created this gist Dec 23, 2010.
    11 changes: 11 additions & 0 deletions django-1.2.4-lookup_allowed-example.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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)