ordering by a foreign key by its attribute name prevents the query from inheriting its related model ordering option (#19195).
(self)
| 436 | ) |
| 437 | |
| 438 | def test_order_by_fk_attname(self): |
| 439 | """ |
| 440 | ordering by a foreign key by its attribute name prevents the query |
| 441 | from inheriting its related model ordering option (#19195). |
| 442 | """ |
| 443 | authors = list(Author.objects.order_by("id")) |
| 444 | for i in range(1, 5): |
| 445 | author = authors[i - 1] |
| 446 | article = getattr(self, "a%d" % (5 - i)) |
| 447 | article.author = author |
| 448 | article.save(update_fields={"author"}) |
| 449 | |
| 450 | self.assertQuerySetEqual( |
| 451 | Article.objects.order_by("author_id"), |
| 452 | [ |
| 453 | "Article 4", |
| 454 | "Article 3", |
| 455 | "Article 2", |
| 456 | "Article 1", |
| 457 | ], |
| 458 | attrgetter("headline"), |
| 459 | ) |
| 460 | |
| 461 | def test_order_by_self_referential_fk(self): |
| 462 | self.a1.author = Author.objects.create(editor=self.author_1) |
nothing calls this directly
no test coverage detected