Skip to content

Instantly share code, notes, and snippets.

@dorosch
Created April 27, 2020 13:35
Show Gist options
  • Save dorosch/8bbc05ae93eb9923cdec8f4877b11575 to your computer and use it in GitHub Desktop.
Save dorosch/8bbc05ae93eb9923cdec8f4877b11575 to your computer and use it in GitHub Desktop.
DRF TimestampField for support unix-timestamp
from datetime import datetime
from rest_framework import serializers
from rest_framework.settings import api_settings
class TimestampField(serializers.Field):
def to_internal_value(self, value):
return datetime.utcfromtimestamp(
int(value)
).strftime(api_settings.DATETIME_FORMAT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment