Skip to content

Instantly share code, notes, and snippets.

@tadeck
Created November 5, 2012 13:02
Show Gist options
  • Save tadeck/4017093 to your computer and use it in GitHub Desktop.
Save tadeck/4017093 to your computer and use it in GitHub Desktop.
Timezone-aware version of TastyPie's DateTimeField
class AwareDateTimeField(DateTimeField):
"""
This field is timezone-aware version of TastyPie standard DateTime field
"""
def convert(self, value):
"""
Convert any value stored in this field to the actual ISO-8601 string
:param value:
:return: deserialized value
:rtype: str or NoneType
"""
# TODO: Consider calling super() here explicitly and using the result
if value is None:
return None
if not isinstance(value, basestring):
# Not fully dehydrated yet
return value.isoformat()
# Nothing to do with it
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment