diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2006-06-30 18:57:23 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2006-06-30 18:57:23 +0000 |
| commit | 0d14498ee00fb505f919410a0513452817ffced9 (patch) | |
| tree | 07f4c0a7893aa3f22c00a7add271790c7e6141b5 | |
| parent | c9032ab07f3694f3ae7da9b0017b764248ce28c9 (diff) | |
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
| -rw-r--r-- | django/db/models/fields/__init__.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 8b000d3c2a..c36cd9808d 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -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': |
