Created
November 5, 2012 13:02
-
-
Save tadeck/4017093 to your computer and use it in GitHub Desktop.
Timezone-aware version of TastyPie's DateTimeField
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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