Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markddavidoff/3cfe7b2de885ba759fb399824895a7c2 to your computer and use it in GitHub Desktop.
Save markddavidoff/3cfe7b2de885ba759fb399824895a7c2 to your computer and use it in GitHub Desktop.
TimestampField drf
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