#6604 closed (fixed)
Custom sort of QuerySet() as list
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
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 |
Description
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=...))
Thanks.
Change History (5)
comment:1 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 16 years ago
Resolution: | invalid → fixed |
---|
comment:5 by , 16 years ago
For anyone who finds this bug while searching for a way to solve the problem,
see this thread for a solution:
http://groups.google.com/group/django-users/browse_thread/thread/341926c0daf90862
Please ask questions like this on the django-users list, not in the bug reporting system.