0
0
mirror of https://github.com/django/django.git synced 2024-12-01 15:42:04 +01:00

Improved DateField.to_python() to catch invalid dates like Feb. 31

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3242 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-06-30 18:57:23 +00:00
parent c9032ab07f
commit 0d14498ee0

View File

@ -406,7 +406,10 @@ class DateField(Field):
if isinstance(value, datetime.date):
return value
validators.isValidANSIDate(value, None)
return datetime.date(*time.strptime(value, '%Y-%m-%d')[:3])
try:
return datetime.date(*time.strptime(value, '%Y-%m-%d')[:3])
except ValueError:
raise validators.ValidationError, gettext('Enter a valid date in YYYY-MM-DD format.')
def get_db_prep_lookup(self, lookup_type, value):
if lookup_type == 'range':