Hi all,
I've downloaded today a new release of Django and played with json
serialization. I found that if you use DateTime field the resulting
json string contains only date, but not all datetime. So I viewed a
source code of django/core/serializers/json.py and found that:
def default(self, o):
if isinstance(o, datetime.date):
return o.strftime(self.DATE_FORMAT)
elif isinstance(o, datetime.time):
return o.strftime(self.TIME_FORMAT)
elif isinstance(o, datetime.datetime):
return o.strftime("%s %s" % (self.DATE_FORMAT,
self.TIME_FORMAT))
....
I know that isinstance(o, datetime.date) returns "True" even "o" is a
datetime object. But I don't know - may be it's a python bug? My python
version 2.4.3 from Ubuntu Dapper. So I replace parts of django code and
all works as I want:
def default(self, o):
if isinstance(o, datetime.datetime):
return o.strftime("%s %s" % (self.DATE_FORMAT,
self.TIME_FORMAT))
elif isinstance(o, datetime.time):
return o.strftime(self.TIME_FORMAT)
elif isinstance(o, datetime.date):
return o.strftime(self.DATE_FORMAT)
else:
return super(self, DateTimeAwareJSONEncoder).defaul
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---