Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#6604 closed (fixed)

Custom sort of QuerySet() as list

Reported by: Alexander Nesterov <alexanderad@…> Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: queryset, sort
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In my table I have values like: 'test1', 'test2', 'test111' and so on, and need to sort them. ORDER BY statement sorts them "wrongly" as strings:
'test2' > 'test4' - false but 'test4' > 'test12' - true.
I can sort this values manually, using list and custom cmp function, but in this situation my sort function will return list instead of QuerySet object, that I need for my ModelChoiceField.
Is there any way to sort QuerySet items as list? (list.sort(cmp=...))

Change History (5)

comment:1 Changed 11 years ago by Malcolm Tredinnick

Resolution: invalid
Status: newclosed

Please ask questions like this on the django-users list, not in the bug reporting system.

comment:2 Changed 11 years ago by Luke Plant

Resolution: invalidfixed

(In [7736]) newforms-admin: Fixed #6604 - removed useless code. Thanks Petr Marhoun, programmerq

comment:3 Changed 11 years ago by Luke Plant

Oops, typo in commit message accidentally closed this. mea culpa.

comment:4 Changed 11 years ago by Collin Anderson

([7736] actually closed #6004)

comment:5 Changed 11 years ago by Paul Winkler

For anyone who finds this bug while searching for a way to solve the problem,
see this thread for a solution:

Note: See TracTickets for help on using tickets.
Back to Top