On Tue, 2009-08-11 at 08:58 -0700, Vokial wrote: > Hi! > In a db i have, already filled up with data, i have a varchar field > which contains dates formatted like "yyyymmdd". Is there a way to make > Django recognise that field as a proper DateField even if the > formatting is different than the usual "yyyy-mm-dd" ?
Django wouldn't recognise a character field that stored the dates in yyyy-mm-dd format as a DateField, either. > Because i can't alter the data in that db and i have to order the > entries by date... One of the reasons yyyymmdd is quite a decent storage format is that normal string sorting puts the dates in order. So why can't you just order on that column as it already stands? You won't be able to do anything like filter using the __month lookup type, because it isn't a date field at the database level. But ordering shouldn't be a problem. > ...maybe by defining a function that automatically decodes the string > into a datetime python object like strptime? You can certainly convert the string values to datetime.date objects easily enough, but that doesn't help with ordering in querysets, for example, since that ordering happens at the database level. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---