Ticket #18530: 18530-admin-filter-incorrect-lookup.diff

File 18530-admin-filter-incorrect-lookup.diff, 3.1 KB (added by Julien Phalip, 12 years ago)
  • django/contrib/admin/filters.py

    diff --git a/django/contrib/admin/filters.py b/django/contrib/admin/filters.py
    index 538bf54..8982f76 100644
    a b from django.core.exceptions import ImproperlyConfigured  
    1212from django.utils.encoding import smart_unicode
    1313from django.utils.translation import ugettext_lazy as _
    1414from django.utils import timezone
    15 
    1615from django.contrib.admin.util import (get_model_from_relation,
    1716    reverse_field_path, get_limit_choices_to_from_path, prepare_lookup_value)
     17from django.contrib.admin.options import IncorrectLookupParameters
    1818
    1919class ListFilter(object):
    2020    title = None  # Human-readable title to appear in the right sidebar.
    class FieldListFilter(ListFilter):  
    129129        return True
    130130
    131131    def queryset(self, request, queryset):
    132         return queryset.filter(**self.used_parameters)
     132        try:
     133            return queryset.filter(**self.used_parameters)
     134        except Exception as e:
     135            raise IncorrectLookupParameters(e)
    133136
    134137    @classmethod
    135138    def register(cls, test, list_filter_class, take_priority=False):
  • tests/regressiontests/admin_views/admin.py

    diff --git a/tests/regressiontests/admin_views/admin.py b/tests/regressiontests/admin_views/admin.py
    index 01a19e6..a88c314 100644
    a b class CustomArticleAdmin(admin.ModelAdmin):  
    127127
    128128
    129129class ThingAdmin(admin.ModelAdmin):
    130     list_filter = ('color__warm', 'color__value')
     130    list_filter = ('color__warm', 'color__value', 'pub_date',)
    131131
    132132
    133133class InquisitionAdmin(admin.ModelAdmin):
  • tests/regressiontests/admin_views/models.py

    diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
    index ab2bc20..e790537 100644
    a b class Color2(Color):  
    118118class Thing(models.Model):
    119119    title = models.CharField(max_length=20)
    120120    color = models.ForeignKey(Color, limit_choices_to={'warm': True})
     121    pub_date = models.DateField(blank=True, null=True)
    121122    def __unicode__(self):
    122123        return self.title
    123124
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index 49ec3c1..58857c9 100644
    a b class AdminViewBasicTest(TestCase):  
    453453        response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'color__id__exact': 'StringNotInteger!'})
    454454        self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)
    455455
     456        # Regression test for #18530
     457        response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'pub_date__gte': 'foo'})
     458        self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)
     459
    456460    def testIsNullLookups(self):
    457461        """Ensure is_null is handled correctly."""
    458462        Article.objects.create(title="I Could Go Anywhere", content="Versatile", date=datetime.datetime.now())
Back to Top