Skip to content

Instantly share code, notes, and snippets.

@blackrobot
Last active December 10, 2015 21:58
Show Gist options
  • Save blackrobot/4498271 to your computer and use it in GitHub Desktop.
Save blackrobot/4498271 to your computer and use it in GitHub Desktop.
class CitedBooksFilter(SimpleListFilter):
title = _('cited book')
parameter_name = 'book_title'
def lookups(self, request, model_admin):
return Citation.objects.exclude(cited_book_id=None).values_list('id', 'title').distinct()
def queryset(self, request, queryset):
if self.value():
queryset = queryset.filter(cited_book_id=self.value())
return queryset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment