Accept datetime values for date fields (by Zloool)

This commit is contained in:
Itai Shirav 2017-01-25 14:48:07 +02:00
parent cce85beeef
commit 9f2619a807

View File

@ -79,6 +79,8 @@ class DateField(Field):
def to_python(self, value): def to_python(self, value):
if isinstance(value, datetime.date): if isinstance(value, datetime.date):
return value return value
if isinstance(value, datetime.datetime):
return value.date()
if isinstance(value, int): if isinstance(value, int):
return DateField.class_default + datetime.timedelta(days=value) return DateField.class_default + datetime.timedelta(days=value)
if isinstance(value, string_types): if isinstance(value, string_types):