mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
parent
f5a8f172a3
commit
ad336cc636
|
@ -536,8 +536,10 @@ class DateField(WritableField):
|
|||
def to_native(self, value):
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
if isinstance(value, datetime.datetime):
|
||||
value = value.date()
|
||||
|
||||
if self.format.lower() == ISO_8601:
|
||||
return value.isoformat()
|
||||
return value.strftime(self.format)
|
||||
|
@ -603,6 +605,7 @@ class DateTimeField(WritableField):
|
|||
def to_native(self, value):
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
if self.format.lower() == ISO_8601:
|
||||
return value.isoformat()
|
||||
return value.strftime(self.format)
|
||||
|
@ -653,8 +656,12 @@ class TimeField(WritableField):
|
|||
raise ValidationError(msg)
|
||||
|
||||
def to_native(self, value):
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
if isinstance(value, datetime.datetime):
|
||||
value = value.time()
|
||||
|
||||
if self.format.lower() == ISO_8601:
|
||||
return value.isoformat()
|
||||
return value.strftime(self.format)
|
||||
|
|
Loading…
Reference in New Issue
Block a user