summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-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)