Django: ordering numerical value with order_by
Posted
by h3
on Stack Overflow
See other posts from Stack Overflow
or by h3
Published on 2010-06-03T20:03:00Z
Indexed on
2010/06/03
20:04 UTC
Read the original article
Hit count: 180
I'm in a situation where I must output a quite large list of objects by a CharField used to store street addresses.
My problem is, that obviously the data is ordered by ASCII codes since it's a Charfield, with the predictable results .. it sort the numbers like this;
1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21....
Now the obvious step would be to change the Charfield the proper field type (IntegerField let's say), however it cannot work since some address might have apartments .. like "128A".
I really don't know how I can order this properly ..
© Stack Overflow or respective owner