fix TimeZoneChoiceField

This commit is contained in:
evgeniy-st 2019-10-24 17:09:08 +03:00
parent 84fb0aec70
commit 2864576c0c

View File

@ -58,7 +58,11 @@ class TimeZoneChoiceField(serializers.ChoiceField):
super().__init__(choices=choices, **kwargs) super().__init__(choices=choices, **kwargs)
def to_representation(self, value): def to_representation(self, value):
return value.zone if isinstance(value, str):
return value
elif isinstance(value, pytz.tzinfo.BaseTzInfo):
return value.zone
return None
def to_internal_value(self, data): def to_internal_value(self, data):
return pytz.timezone(data) return pytz.timezone(data)