4👍
✅
The simple workaround for this is adding own serializer:
class ISO8601UTCOffsetSerializer(Serializer):
"""
Default is ``iso-8601``, which looks like "2014-01-21T19:31:58.150273+00:00".
"""
# Tastypie>=0.9.6,<=0.11.0
def format_datetime(self, data):
# data = make_naive(data) # Skipping this line..
if self.datetime_formatting == 'rfc-2822':
return dateformat.format(make_naive(data), 'r')
if self.datetime_formatting == 'iso-8601-strict':
# Remove microseconds to strictly adhere to iso-8601
data = data - datetime.timedelta(microseconds=data.microsecond)
return data.isoformat()
class MyResource(BaseModelResource):
class Meta:
serializer = ISO8601UTCOffsetSerializer(formats=['json'])
Tastypie has thrown away timezone info and convert aware datetime to server datetime without timezone info. The above code shows how to fix it. Tastypie does it because some incompatibility with MySQL databases and back-compability with older Django versions I guess, discussion about is on github.
Source:stackexchange.com