diff options
| author | Simon Charette <charette.s@gmail.com> | 2016-02-19 12:47:24 -0500 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2016-03-02 16:08:37 -0500 |
| commit | 5d240b070d744f9a2f4cc3117306ea861d866019 (patch) | |
| tree | 292e297298663da45976fb037a699c3afd0fc33e /tests | |
| parent | 1d17bb4f7d78f6c3df9dedc0710acc5bdb300693 (diff) | |
Refs #17001 -- Added a test for custom prefetch related queryset on generic relations.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/prefetch_related/tests.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/prefetch_related/tests.py b/tests/prefetch_related/tests.py index 494011486c..d8c1458ce2 100644 --- a/tests/prefetch_related/tests.py +++ b/tests/prefetch_related/tests.py @@ -836,6 +836,19 @@ class GenericRelationTests(TestCase): self.assertEqual(sorted([i.tag for i in bookmark.tags.all()]), ["django", "python"]) self.assertEqual([i.tag for i in bookmark.favorite_tags.all()], ["python"]) + def test_custom_queryset(self): + bookmark = Bookmark.objects.create(url='http://www.djangoproject.com/') + django_tag = TaggedItem.objects.create(content_object=bookmark, tag='django') + TaggedItem.objects.create(content_object=bookmark, tag='python') + + with self.assertNumQueries(2): + bookmark = Bookmark.objects.prefetch_related( + Prefetch('tags', TaggedItem.objects.filter(tag='django')), + ).get() + + with self.assertNumQueries(0): + self.assertEqual(list(bookmark.tags.all()), [django_tag]) + class MultiTableInheritanceTest(TestCase): |
