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:
parent
c9032ab07f
commit
0d14498ee0
|
@ -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':
|
||||
|
|
Loading…
Reference in New Issue