diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-09-24 09:45:51 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-09-25 10:09:28 +0200 |
commit | e4ab44a4b2ef70be09c35c9197a19fd2e993b4d6 (patch) | |
tree | 2dfaa9b004c4089f81472020223c1e8ab164a0c8 /tests/admin_filters | |
parent | 33e91f3ed8ce6412d9d0964acb59166579b9b20c (diff) | |
download | django-e4ab44a4b2ef70be09c35c9197a19fd2e993b4d6.tar.gz |
Fixed #32038 -- Fixed EmptyFieldListFilter crash with GenericRelation.
Thanks Javier Matos Odut for the report.
Diffstat (limited to 'tests/admin_filters')
-rw-r--r-- | tests/admin_filters/tests.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/admin_filters/tests.py b/tests/admin_filters/tests.py index 6986afb64a..2ad44b6c8c 100644 --- a/tests/admin_filters/tests.py +++ b/tests/admin_filters/tests.py @@ -1535,6 +1535,32 @@ class ListFiltersTests(TestCase): queryset = changelist.get_queryset(request) self.assertCountEqual(queryset, expected_result) + def test_emptylistfieldfilter_genericrelation(self): + class BookmarkGenericRelation(ModelAdmin): + list_filter = ( + ('tags', EmptyFieldListFilter), + ) + + modeladmin = BookmarkGenericRelation(Bookmark, site) + + django_bookmark = Bookmark.objects.create(url='https://www.djangoproject.com/') + python_bookmark = Bookmark.objects.create(url='https://www.python.org/') + none_tags = Bookmark.objects.create(url='https://www.kernel.org/') + TaggedItem.objects.create(content_object=django_bookmark, tag='python') + TaggedItem.objects.create(content_object=python_bookmark, tag='python') + + tests = [ + ({'tags__isempty': '1'}, [none_tags]), + ({'tags__isempty': '0'}, [django_bookmark, python_bookmark]), + ] + for query_string, expected_result in tests: + with self.subTest(query_string=query_string): + request = self.request_factory.get('/', query_string) + request.user = self.alfred + changelist = modeladmin.get_changelist_instance(request) + queryset = changelist.get_queryset(request) + self.assertCountEqual(queryset, expected_result) + def test_emptylistfieldfilter_choices(self): modeladmin = BookAdminWithEmptyFieldListFilter(Book, site) request = self.request_factory.get('/') |