Opened 2 years ago
Closed 2 years ago
#34089 closed Bug (duplicate)
Order by foreign key is not respected when using expression as default ordering
Description ¶
I recently switched a bunch of
ordering = ["name"]
to
ordering = [Lower("name")]
in the Meta class of some models.
Now when I order a related Model, the result is not order as it should be.
Consider the following example:
class ItemCategory(models.Model): name = models.CharField(max_length=100) class Meta: ordering = [Lower("name")] class Item(models.Model): name = models.CharField(max_length=100) category = models.ForeignKey("ItemCategory", blank=True, null=True, on_delete=models.CASCADE) class Meta: ordering = [Lower("name")]
If I do Item.objects.all().order_by("category", "name")
then the results are ordered by Item name only, not ItemCategory name and Item name as it should be.
Note:
See TracTickets
for help on using tickets.
Duplicate of #29538, fixed in Django 4.1 (see 2798c937deb6625a4e6a36e70d4d60ce5faac954).