mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 03:23:59 +03:00
Patched DateField and DateTimeField to check for None values before trying to perform date(time) conversion.
Signed-off-by: Kevin Stone <kevinastone@gmail.com>
This commit is contained in:
parent
6bea275de8
commit
2f8d8b499e
|
@ -534,6 +534,8 @@ class DateField(WritableField):
|
|||
raise ValidationError(msg)
|
||||
|
||||
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:
|
||||
|
@ -599,6 +601,8 @@ class DateTimeField(WritableField):
|
|||
raise ValidationError(msg)
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user