From a55fa029f765fb824d6227a4d3bf6e7fbcd1c260 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Fri, 28 Jul 2006 00:13:10 +0000 Subject: [PATCH] Fixed #1767 -- boolean fields may now have validators! Thanks, Joseph. git-svn-id: http://code.djangoproject.com/svn/django/trunk@3467 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/fields/__init__.py | 4 ++-- django/forms/__init__.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 6fba7f7876..516f4b1538 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -247,9 +247,9 @@ class Field(object): params['is_required'] = not self.blank and not self.primary_key and not rel # BooleanFields (CheckboxFields) are a special case. They don't take - # is_required or validator_list. + # is_required. if isinstance(self, BooleanField): - del params['validator_list'], params['is_required'] + del params['is_required'] # If this field is in a related context, check whether any other fields # in the related object have core=True. If so, add a validator -- diff --git a/django/forms/__init__.py b/django/forms/__init__.py index 4907bd76f7..730f7a54da 100644 --- a/django/forms/__init__.py +++ b/django/forms/__init__.py @@ -434,10 +434,12 @@ class HiddenField(FormField): (self.get_id(), self.field_name, escape(data)) class CheckboxField(FormField): - def __init__(self, field_name, checked_by_default=False): + def __init__(self, field_name, checked_by_default=False, validator_list=None): + if validator_list is None: validator_list = [] self.field_name = field_name self.checked_by_default = checked_by_default - self.is_required, self.validator_list = False, [] # because the validator looks for these + self.is_required = False # because the validator looks for these + self.validator_list = validator_list[:] def render(self, data): checked_html = ''