﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
11771	Support filtering by non-database (queryset) fields in the admin	Samuel Cormier-Iijima	nobody	"It's currently impossible to filter the admin interface by non-database fields, even if the fields are being selected in the queryset.

The attached patch lets you do something like this:

{{{
class Author(models.Model):
	name = models.CharField(max_length=255)

class Book(models.Model):
	author = models.ForeignKey(Author)

class AuthorAdmin(admin.ModelAdmin):
	list_display = ['name', 'books']
	list_filter = [models.IntegerField(verbose_name='number of books', name='num_books')]

	def books(self, obj):
		return obj.num_books
	books.short_description = 'Number of books'

	def queryset(self, request):
		return super(AuthorAdmin, self).queryset(request).annotate(num_books=models.Count('book'))

admin.site.register(Author, AuthorAdmin)
admin.site.register(Book)
}}}

which would show all of the values for num_books in the available filters. (This particular example only works in MySQL, but could be applied to fields selected with .extra(select=...) instead of .annotate)."		closed	contrib.admin	dev		duplicate	admin, filtering, filter, filterspec, fields	sciyoshi@… ramusus@…	Accepted	1	1	1	1	0	0
