Ticket #1767: boolean_validator_list2.patch

File boolean_validator_list2.patch, 1.6 KB (added by Alex Dedul, 18 years ago)

Added mutable default arguments fix

  • django/db/models/fields/__init__.py

     
    247247        params['is_required'] = not self.blank and not self.primary_key and not rel
    248248
    249249        # BooleanFields (CheckboxFields) are a special case. They don't take
    250         # is_required or validator_list.
     250        # is_required.
    251251        if isinstance(self, BooleanField):
    252             del params['validator_list'], params['is_required']
     252            del params['is_required']
    253253
    254254        # If this field is in a related context, check whether any other fields
    255255        # in the related object have core=True. If so, add a validator --
  • django/forms/__init__.py

     
    434434            (self.get_id(), self.field_name, escape(data))
    435435
    436436class CheckboxField(FormField):
    437     def __init__(self, field_name, checked_by_default=False):
     437    def __init__(self, field_name, checked_by_default=False, validator_list=None):
     438        if validator_list is None: validator_list = []
    438439        self.field_name = field_name
    439440        self.checked_by_default = checked_by_default
    440         self.is_required, self.validator_list = False, [] # because the validator looks for these
     441        self.is_required = False # because the validator looks for these
     442        self.validator_list = validator_list[:]
    441443
    442444    def render(self, data):
    443445        checked_html = ''
Back to Top