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
1 changed files with 4 additions and 1 deletions

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':