Hi all,

I recently solved a problem with a field that could not be ordered as I 
wanted. It was a CharField containing of exactly seven numbers like 
9900000, 0100000, 1200000 etc. The first two digits indicated a year (99 
being 1999 and 12 being 2012). The ordering should be different from usual, 
namely:
5000000, 5000001, ..., 0000000, 0000001, ... , 4999999. So I hacked around 
with a model manager, and a special QuerySet, and reached a state with 
which I was almost satisfied. See http://djangosnippets.org/snippets/2861/ 
for the whole stuff. 

There is even a special feature (totally optional) for databases which can 
do functional indexes to speed up the ordering. Sqlite would still work, 
although not quite as fast.

I can think of a  couple of other similar use cases e.g. a field containing 
strings like 'a1', 'a9', 'a10', 'a100' etc. where the usual alphanumeric 
sorting does not make sense.

If there is enough interest, I could dig into Django core to make this 
whole functionality more generic, so it could be merged into a development 
branch in Django.

I'd love to read some thoughts from you how / if I should continue from 
here.

Martin

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-developers/-/-CV6h3o6z2YJ.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to