Index: contrib/admin/validation.py
===================================================================
--- contrib/admin/validation.py	(revisÆo 9781)
+++ contrib/admin/validation.py	(c¢pia de trabalho)
@@ -6,6 +6,7 @@
 from django.core.exceptions import ImproperlyConfigured
 from django.db import models
 from django.forms.models import BaseModelForm, BaseModelFormSet, fields_for_model
+from django.contrib.admin.filterspecs import FieldFilterSpec
 from django.contrib.admin.options import flatten_fieldsets, BaseModelAdmin
 from django.contrib.admin.options import HORIZONTAL, VERTICAL
 
@@ -54,8 +55,20 @@
     # list_filter
     if hasattr(cls, 'list_filter'):
         check_isseq(cls, 'list_filter', cls.list_filter)
-        for idx, field in enumerate(cls.list_filter):
-            get_field(cls, model, opts, 'list_filter[%d]' % idx, field)
+        for idx, item in enumerate(cls.list_filter):
+            if callable(item):
+                #TODO find out whether item  is of type FilterSpec
+                pass
+            else:
+                if type(item) is tuple:
+                    (field, factory) = item
+                        #TODO find out whether factory is of type (or a descendant of) FieldFilterSpec
+                        #raise ImproperlyConfigured("'%s.list_filter[%d][1]' is not of type FieldFilterSpec."  
+                        #    % (cls.__name__, idx))
+                else:
+                    field = item
+                # validate field
+                get_field(cls, model, opts, 'list_filter[%d]' % idx, field)
 
     # list_per_page = 100
     if hasattr(cls, 'list_per_page') and not isinstance(cls.list_per_page, int):
Index: contrib/admin/filterspecs.py
===================================================================
--- contrib/admin/filterspecs.py	(revisÆo 9781)
+++ contrib/admin/filterspecs.py	(c¢pia de trabalho)
@@ -14,21 +14,10 @@
 import datetime
 
 class FilterSpec(object):
-    filter_specs = []
-    def __init__(self, f, request, params, model, model_admin):
-        self.field = f
+
+    def __init__(self, request, params, model, model_admin):
         self.params = params
 
-    def register(cls, test, factory):
-        cls.filter_specs.append((test, factory))
-    register = classmethod(register)
-
-    def create(cls, f, request, params, model, model_admin):
-        for test, factory in cls.filter_specs:
-            if test(f):
-                return factory(f, request, params, model, model_admin)
-    create = classmethod(create)
-
     def has_output(self):
         return True
 
@@ -36,7 +25,11 @@
         raise NotImplementedError()
 
     def title(self):
-        return self.field.verbose_name
+        raise NotImplementedError()
+    
+    def get_query_set(self, cl, qs):
+        return qs
+        
 
     def output(self, cl):
         t = []
@@ -51,9 +44,28 @@
             t.append('</ul>\n\n')
         return mark_safe("".join(t))
 
-class RelatedFilterSpec(FilterSpec):
-    def __init__(self, f, request, params, model, model_admin):
-        super(RelatedFilterSpec, self).__init__(f, request, params, model, model_admin)
+class FieldFilterSpec(FilterSpec):
+    field_filter_specs = []
+    def __init__(self, request, params, model, model_admin, field):
+        super(FieldFilterSpec, self).__init__(request, params, model, model_admin)
+        self.field = field
+        
+    def register(cls, test, factory):
+        cls.field_filter_specs.append((test, factory))
+    register = classmethod(register)
+
+    def title(self):
+        return self.field.verbose_name
+    
+    def create(cls, request, params, model, model_admin, field):
+        for test, factory in cls.field_filter_specs:
+            if test(field):
+                return factory(request, params, model, model_admin, field)
+    create = classmethod(create)
+
+class RelatedFilterSpec(FieldFilterSpec):
+    def __init__(self, request, params, model, model_admin, f):
+        super(RelatedFilterSpec, self).__init__(request, params, model, model_admin, f)
         if isinstance(f, models.ManyToManyField):
             self.lookup_title = f.rel.to._meta.verbose_name
         else:
@@ -77,11 +89,11 @@
                    'query_string': cl.get_query_string({self.lookup_kwarg: pk_val}),
                    'display': val}
 
-FilterSpec.register(lambda f: bool(f.rel), RelatedFilterSpec)
+FieldFilterSpec.register(lambda f: bool(f.rel), RelatedFilterSpec)
 
-class ChoicesFilterSpec(FilterSpec):
-    def __init__(self, f, request, params, model, model_admin):
-        super(ChoicesFilterSpec, self).__init__(f, request, params, model, model_admin)
+class ChoicesFilterSpec(FieldFilterSpec):
+    def __init__(self, request, params, model, model_admin, f):
+        super(ChoicesFilterSpec, self).__init__(request, params, model, model_admin, f)
         self.lookup_kwarg = '%s__exact' % f.name
         self.lookup_val = request.GET.get(self.lookup_kwarg, None)
 
@@ -94,11 +106,11 @@
                     'query_string': cl.get_query_string({self.lookup_kwarg: k}),
                     'display': v}
 
-FilterSpec.register(lambda f: bool(f.choices), ChoicesFilterSpec)
+FieldFilterSpec.register(lambda f: bool(f.choices), ChoicesFilterSpec)
 
-class DateFieldFilterSpec(FilterSpec):
-    def __init__(self, f, request, params, model, model_admin):
-        super(DateFieldFilterSpec, self).__init__(f, request, params, model, model_admin)
+class DateFieldFilterSpec(FieldFilterSpec):
+    def __init__(self, request, params, model, model_admin, f):
+        super(DateFieldFilterSpec, self).__init__(request, params, model, model_admin, f)
 
         self.field_generic = '%s__' % self.field.name
 
@@ -129,11 +141,11 @@
                    'query_string': cl.get_query_string(param_dict, [self.field_generic]),
                    'display': title}
 
-FilterSpec.register(lambda f: isinstance(f, models.DateField), DateFieldFilterSpec)
+FieldFilterSpec.register(lambda f: isinstance(f, models.DateField), DateFieldFilterSpec)
 
-class BooleanFieldFilterSpec(FilterSpec):
-    def __init__(self, f, request, params, model, model_admin):
-        super(BooleanFieldFilterSpec, self).__init__(f, request, params, model, model_admin)
+class BooleanFieldFilterSpec(FieldFilterSpec):
+    def __init__(self, request, params, model, model_admin, f):
+        super(BooleanFieldFilterSpec, self).__init__(request, params, model, model_admin, f)
         self.lookup_kwarg = '%s__exact' % f.name
         self.lookup_kwarg2 = '%s__isnull' % f.name
         self.lookup_val = request.GET.get(self.lookup_kwarg, None)
@@ -152,14 +164,14 @@
                    'query_string': cl.get_query_string({self.lookup_kwarg2: 'True'}, [self.lookup_kwarg]),
                    'display': _('Unknown')}
 
-FilterSpec.register(lambda f: isinstance(f, models.BooleanField) or isinstance(f, models.NullBooleanField), BooleanFieldFilterSpec)
+FieldFilterSpec.register(lambda f: isinstance(f, models.BooleanField) or isinstance(f, models.NullBooleanField), BooleanFieldFilterSpec)
 
 # This should be registered last, because it's a last resort. For example,
 # if a field is eligible to use the BooleanFieldFilterSpec, that'd be much
 # more appropriate, and the AllValuesFilterSpec won't get used for it.
-class AllValuesFilterSpec(FilterSpec):
-    def __init__(self, f, request, params, model, model_admin):
-        super(AllValuesFilterSpec, self).__init__(f, request, params, model, model_admin)
+class AllValuesFilterSpec(FieldFilterSpec):
+    def __init__(self, request, params, model, model_admin, f):
+        super(AllValuesFilterSpec, self).__init__(request, params, model, model_admin, f)
         self.lookup_val = request.GET.get(f.name, None)
         self.lookup_choices = model_admin.queryset(request).distinct().order_by(f.name).values(f.name)
 
@@ -175,4 +187,4 @@
             yield {'selected': self.lookup_val == val,
                    'query_string': cl.get_query_string({self.field.name: val}),
                    'display': val}
-FilterSpec.register(lambda f: True, AllValuesFilterSpec)
+FieldFilterSpec.register(lambda f: True, AllValuesFilterSpec)
Index: contrib/admin/views/main.py
===================================================================
--- contrib/admin/views/main.py	(revisÆo 9781)
+++ contrib/admin/views/main.py	(c¢pia de trabalho)
@@ -1,4 +1,5 @@
 from django.contrib.admin.filterspecs import FilterSpec
+from django.contrib.admin.filterspecs import FieldFilterSpec
 from django.contrib.admin.options import IncorrectLookupParameters
 from django.contrib.admin.util import quote
 from django.core.paginator import Paginator, InvalidPage
@@ -62,20 +63,30 @@
         if ERROR_FLAG in self.params:
             del self.params[ERROR_FLAG]
 
+        self.filter_specs, self.has_filters = self.get_filters(request)
+        
         self.order_field, self.order_type = self.get_ordering()
         self.query = request.GET.get(SEARCH_VAR, '')
         self.query_set = self.get_query_set()
         self.get_results(request)
         self.title = (self.is_popup and ugettext('Select %s') % force_unicode(self.opts.verbose_name) or ugettext('Select %s to change') % force_unicode(self.opts.verbose_name))
-        self.filter_specs, self.has_filters = self.get_filters(request)
+
         self.pk_attname = self.lookup_opts.pk.attname
 
     def get_filters(self, request):
         filter_specs = []
         if self.list_filter:
-            filter_fields = [self.lookup_opts.get_field(field_name) for field_name in self.list_filter]
-            for f in filter_fields:
-                spec = FilterSpec.create(f, request, self.params, self.model, self.model_admin)
+            for item in self.list_filter:
+                if callable(item):
+                    spec = item(request, self.params, self.model, self.model_admin)
+                else:
+                    if type(item) is tuple:
+                        (name, factory) = item
+                    else:
+                        name = item
+                        factory = FieldFilterSpec.create
+                    f = self.lookup_opts.get_field(name)
+                    spec = factory(request, self.params, self.model, self.model_admin, f)
                 if spec and spec.has_output():
                     filter_specs.append(spec)
         return filter_specs, bool(filter_specs)
@@ -169,6 +180,12 @@
 
     def get_query_set(self):
         qs = self.root_query_set
+        
+        # let every filter do its filtering
+        for filter_spec in self.filter_specs:
+            tqs = filter_spec.get_query_set(self, qs)
+            if tqs != None: qs = tqs
+        
         lookup_params = self.params.copy() # a dictionary of the query string
         for i in (ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR):
             if i in lookup_params:
@@ -178,8 +195,16 @@
                 # 'key' will be used as a keyword argument later, so Python
                 # requires it to be a string.
                 del lookup_params[key]
-                lookup_params[smart_str(key)] = value
+                key = smart_str(key)
+                lookup_params[key] = value
 
+            from django.db.models.sql.constants import LOOKUP_SEP
+            try:
+                f = self.opts.get_field(key.split(LOOKUP_SEP)[0])
+            except models.FieldDoesNotExist:
+                del lookup_params[key]
+                continue
+
             # if key ends with __in, split parameter into separate values
             if key.endswith('__in'):
                 lookup_params[key] = value.split(',')
