|
9 | 9 | from django_filters import FilterSet as DFFilterSet |
10 | 10 |
|
11 | 11 | from .testapp.models import ( |
12 | | - User, Note, Post, Cover, A, B, C, Person, Tag, BlogPost, |
| 12 | + User, Note, Post, Cover, Page, A, B, C, Person, Tag, BlogPost, |
13 | 13 | ) |
14 | 14 |
|
15 | 15 | from .testapp.filters import ( |
|
18 | 18 | PostFilter, |
19 | 19 | BlogPostFilter, |
20 | 20 | CoverFilterWithRelated, |
| 21 | + PageFilterWithAliasedNestedRelated, |
21 | 22 | NoteFilterWithAll, |
22 | 23 | NoteFilterWithRelated, |
23 | 24 | NoteFilterWithRelatedDifferentName, |
@@ -110,11 +111,13 @@ def setUpTestData(cls): |
110 | 111 | Cover.objects.create(post=post1, comment="Cover 1") |
111 | 112 | Cover.objects.create(post=post3, comment="Cover 2") |
112 | 113 |
|
113 | | - # ####################### |
114 | | - # # Create pages |
115 | | - # ####################### |
116 | | - # page1 = Page.objects.create(title="First page", content="First first.") |
117 | | - # Page.objects.create(title="Second page", content="Second second.", previous_page=page1) |
| 114 | + ####################### |
| 115 | + # Create pages |
| 116 | + ####################### |
| 117 | + Page.objects.create(title="First page", content="First first.") |
| 118 | + Page.objects.create(title="Second page", content="Second second.", previous_page_id=1) |
| 119 | + Page.objects.create(title="Third page", content="Third third.", previous_page_id=2) |
| 120 | + Page.objects.create(title="Fourth page", content="Fourth fourth.", previous_page_id=3) |
118 | 121 |
|
119 | 122 | ################################ |
120 | 123 | # ManyToMany |
@@ -220,6 +223,19 @@ def test_relatedfilter_for_related_alllookups_and_different_filter_name(self): |
220 | 223 | f = NoteFilterWithRelatedAllDifferentFilterName(GET, queryset=Note.objects.all()) |
221 | 224 | self.assertEqual(len(list(f.qs)), 4) |
222 | 225 |
|
| 226 | + def test_relatedfilter_for_aliased_nested_relationships(self): |
| 227 | + qs = Page.objects.order_by('pk') |
| 228 | + |
| 229 | + f1 = PageFilterWithAliasedNestedRelated({'two_pages_back': '1'}, queryset=qs) |
| 230 | + f2 = PageFilterWithAliasedNestedRelated({'two_pages_back': '2'}, queryset=qs) |
| 231 | + f3 = PageFilterWithAliasedNestedRelated({'two_pages_back': '3'}, queryset=qs) |
| 232 | + f4 = PageFilterWithAliasedNestedRelated({'two_pages_back': '4'}, queryset=qs) |
| 233 | + |
| 234 | + self.assertQuerysetEqual(f1.qs, [3], lambda p: p.pk) |
| 235 | + self.assertQuerysetEqual(f2.qs, [4], lambda p: p.pk) |
| 236 | + self.assertQuerysetEqual(f3.qs, [], lambda p: p.pk) |
| 237 | + self.assertQuerysetEqual(f4.qs, [], lambda p: p.pk) |
| 238 | + |
223 | 239 | def test_relatedfilter_different_name(self): |
224 | 240 | # Test the name filter on the related UserFilter set. |
225 | 241 | GET = { |
|
0 commit comments