#32685: Add feature to preserve order in .filter(field__in=list) query
-------------------------------------------+------------------------
               Reporter:  Barney Szabolcs  |          Owner:  nobody
                   Type:  Uncategorized    |         Status:  new
              Component:  Uncategorized    |        Version:  2.2
               Severity:  Normal           |       Keywords:
           Triage Stage:  Unreviewed       |      Has patch:  0
    Needs documentation:  0                |    Needs tests:  0
Patch needs improvement:  0                |  Easy pickings:  0
                  UI/UX:  0                |
-------------------------------------------+------------------------
 filter {{{__in}}} query does not guarantee to preserve order, so I usually
 sort afterwards using python's sort.

 However, in **django admin** I cannot sort queries using python's sort
 when manipulating the QuerySet
 since I have to return a QuerySet.
 So, I'd do something like
 {{{
 queryset.filter(my_field__in=values).raw(
     f'order by array_position(ARRAY[{ ",".join(["%s"]*len(values))
 }]::varchar[], my_field)',
     params=values)
  }}}
 but this does not work...
 is there a solution here?  (I cannot use raw either since I have a
 queryset input argument to work with)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32685>
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/059.4884e958e162cb87bb61a9641bd71b26%40djangoproject.com.

Reply via email to