#34089: Order by foreign key is not respected when using expression as default
ordering
-------------------------------------+-------------------------------------
               Reporter:  rptmat57   |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  3.2
  layer (models, ORM)                |       Keywords:  order_by
               Severity:  Normal     |  foreign_key
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34089>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070183ccf6bfd0-8e80c9a4-6223-4e66-a831-351f4ddacbe2-000000%40eu-central-1.amazonses.com.

Reply via email to