Created
April 27, 2020 13:35
-
-
Save dorosch/8bbc05ae93eb9923cdec8f4877b11575 to your computer and use it in GitHub Desktop.
DRF TimestampField for support unix-timestamp
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
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