MCPcopy
hub / github.com/django/django / test_order_by_fk_attname

Method test_order_by_fk_attname

tests/ordering/tests.py:438–459  ·  view source on GitHub ↗

ordering by a foreign key by its attribute name prevents the query from inheriting its related model ordering option (#19195).

(self)

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 3

order_byMethod · 0.80
assertQuerySetEqualMethod · 0.80
saveMethod · 0.45

Tested by

no test coverage detected