Author: kmtracey
Date: 2010-03-16 14:01:40 -0500 (Tue, 16 Mar 2010)
New Revision: 12795

Modified:
   django/trunk/django/contrib/admin/views/main.py
   django/trunk/tests/regressiontests/admin_views/models.py
   django/trunk/tests/regressiontests/admin_views/tests.py
Log:
Fixed #12105: Corrected handling of isnull=False lookups in admin. Thanks 
marcob, Travis Cline, gabrielhurley.



Modified: django/trunk/django/contrib/admin/views/main.py
===================================================================
--- django/trunk/django/contrib/admin/views/main.py     2010-03-16 16:10:27 UTC 
(rev 12794)
+++ django/trunk/django/contrib/admin/views/main.py     2010-03-16 19:01:40 UTC 
(rev 12795)
@@ -185,6 +185,13 @@
             if key.endswith('__in'):
                 lookup_params[key] = value.split(',')
 
+            # if key ends with __isnull, special case '' and false
+            if key.endswith('__isnull'):
+                if value.lower() in ('', 'false'):
+                    lookup_params[key] = False
+                else:
+                    lookup_params[key] = True
+
         # Apply lookup parameters from the query string.
         try:
             qs = qs.filter(**lookup_params)

Modified: django/trunk/tests/regressiontests/admin_views/models.py
===================================================================
--- django/trunk/tests/regressiontests/admin_views/models.py    2010-03-16 
16:10:27 UTC (rev 12794)
+++ django/trunk/tests/regressiontests/admin_views/models.py    2010-03-16 
19:01:40 UTC (rev 12795)
@@ -27,7 +27,7 @@
     title = models.CharField(max_length=100)
     content = models.TextField()
     date = models.DateTimeField()
-    section = models.ForeignKey(Section)
+    section = models.ForeignKey(Section, null=True, blank=True)
 
     def __unicode__(self):
         return self.title

Modified: django/trunk/tests/regressiontests/admin_views/tests.py
===================================================================
--- django/trunk/tests/regressiontests/admin_views/tests.py     2010-03-16 
16:10:27 UTC (rev 12794)
+++ django/trunk/tests/regressiontests/admin_views/tests.py     2010-03-16 
19:01:40 UTC (rev 12795)
@@ -217,6 +217,16 @@
         response = self.client.get('/test_admin/%s/admin_views/thing/' % 
self.urlbit, {'color__id__exact': 'StringNotInteger!'})
         self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' 
% self.urlbit)
 
+    def testIsNullLookups(self):
+        """Ensure is_null is handled correctly."""
+        Article.objects.create(title="I Could Go Anywhere", 
content="Versatile", date=datetime.datetime.now())
+        response = self.client.get('/test_admin/%s/admin_views/article/' % 
self.urlbit)
+        self.assertTrue('4 articles' in response.content, '"4 articles" 
missing from response')
+        response = self.client.get('/test_admin/%s/admin_views/article/' % 
self.urlbit, {'section__isnull': 'false'})
+        self.assertTrue('3 articles' in response.content, '"3 articles" 
missing from response')
+        response = self.client.get('/test_admin/%s/admin_views/article/' % 
self.urlbit, {'section__isnull': 'true'})
+        self.assertTrue('1 article' in response.content, '"1 article" missing 
from response')
+
     def testLogoutAndPasswordChangeURLs(self):
         response = self.client.get('/test_admin/%s/admin_views/article/' % 
self.urlbit)
         self.failIf('<a href="/test_admin/%s/logout/">' % self.urlbit not in 
response.content)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to