Created
April 23, 2019 19:32
-
-
Save markddavidoff/3cfe7b2de885ba759fb399824895a7c2 to your computer and use it in GitHub Desktop.
TimestampField drf
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 TimestampField(serializers.DateTimeField): | |
def to_internal_value(self, value): | |
value = datetime.utcfromtimestamp(value) | |
return super(TimestampField, self).to_internal_value(value) | |
def to_representation(self, value): | |
if not value: | |
return value | |
return value.timestamp() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment