#24747: Allow transforms in order_by
-------------------------------------+-------------------------------------
     Reporter:  Ben Buchwald         |                    Owner:  Matthew
                                     |  Wilkes
         Type:  New feature          |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Austin Roberts):

 As I noted on #28168, I found a work around for this, though it would
 still be great to have this work the same way as filter.

 For now, I'm able to work around this by instead doing:

 {{{
 from django.db.models.expressions import OrderBy, RawSQL

 MyModel.objects.all().order_by(OrderBy(RawSQL("metadata #> '{some}' #>
 '{field}'", []))
 }}}

 Similarly, I have cases where I want to be able to do

 {{{
 MyModel.objects.all().values("metadata__some__field")
 }}}

 I've worked out a similar work around of

 {{{
 MyModel.objects.all().annotate(some_field=RawSQL("metadata #> '{some}' #>
 '{field}'", [])).values("some_field")
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24747#comment:7>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.10ff0a44950dc54b4dd7a790eac6fd11%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to