summaryrefslogtreecommitdiff
path: root/tests/admin_filters
diff options
context:
space:
mode:
authorVincenzo Pandolfo <pandolfovince@gmail.com>2016-03-30 16:05:31 +0100
committerTim Graham <timograham@gmail.com>2016-05-12 12:40:14 -0400
commit069319396f0e9fb10254e1bcf578336392c9cffb (patch)
tree55d55b78f25dd8c939e71042c2902911aa353512 /tests/admin_filters
parent929684d6ee0efb5afad51dc584489d0437d2451b (diff)
downloaddjango-069319396f0e9fb10254e1bcf578336392c9cffb.tar.gz
Fixed #26277 -- Added support for null values in ChoicesFieldListFilter.
Diffstat (limited to 'tests/admin_filters')
-rw-r--r--tests/admin_filters/models.py7
-rw-r--r--tests/admin_filters/tests.py16
2 files changed, 23 insertions, 0 deletions
diff --git a/tests/admin_filters/models.py b/tests/admin_filters/models.py
index db37958882..8860201d35 100644
--- a/tests/admin_filters/models.py
+++ b/tests/admin_filters/models.py
@@ -75,5 +75,12 @@ class Bookmark(models.Model):
url = models.URLField()
tags = GenericRelation(TaggedItem)
+ CHOICES = [
+ ('a', 'A'),
+ (None, 'None'),
+ ('', '-'),
+ ]
+ none_or_null = models.CharField(max_length=20, choices=CHOICES, blank=True, null=True)
+
def __str__(self):
return self.url
diff --git a/tests/admin_filters/tests.py b/tests/admin_filters/tests.py
index 3d2f7ab9c6..ba6934f4ed 100644
--- a/tests/admin_filters/tests.py
+++ b/tests/admin_filters/tests.py
@@ -302,6 +302,22 @@ class ListFiltersTests(TestCase):
modeladmin.list_max_show_all, modeladmin.list_editable, modeladmin,
)
+ def test_choicesfieldlistfilter_has_none_choice(self):
+ """
+ The last choice is for the None value.
+ """
+ class BookmarkChoicesAdmin(ModelAdmin):
+ list_display = ['none_or_null']
+ list_filter = ['none_or_null']
+
+ modeladmin = BookmarkChoicesAdmin(Bookmark, site)
+ request = self.request_factory.get('/', {})
+ changelist = self.get_changelist(request, Bookmark, modeladmin)
+ filterspec = changelist.get_filters(request)[0][0]
+ choices = list(filterspec.choices(changelist))
+ self.assertEqual(choices[-1]['display'], 'None')
+ self.assertEqual(choices[-1]['query_string'], '?none_or_null__isnull=True')
+
def test_datefieldlistfilter(self):
modeladmin = BookAdmin(Book, site)