Ticket #570: 570.2.diff
File 570.2.diff, 2.3 KB (added by , 19 years ago) |
---|
-
django/core/formfields.py
116 116 if field.field_name == key: 117 117 if hasattr(field, 'requires_data_list') and hasattr(self.data, 'getlist'): 118 118 data = self.data.getlist(field.field_name) 119 elif hasattr(field, 'db_field_name'): 120 data = self.data.get(field.db_field_name, None) 119 121 else: 120 122 data = self.data.get(field.field_name, None) 121 123 if data is None: … … 300 302 html2python = staticmethod(html2python) 301 303 302 304 class SelectField(FormField): 303 def __init__(self, field_name, choices=[], size=1, is_required=False, validator_list=[]):305 def __init__(self, field_name, db_field_name=None, choices=[], size=1, is_required=False, validator_list=[]): 304 306 self.field_name = field_name 307 if db_field_name: 308 self.db_field_name = db_field_name 305 309 # choices is a list of (value, human-readable key) tuples because order matters 306 310 self.choices, self.size, self.is_required = choices, size, is_required 307 311 self.validator_list = [self.isValidChoice] + validator_list … … 309 313 def render(self, data): 310 314 output = ['<select id="%s" class="v%s%s" name="%s" size="%s">' % \ 311 315 (FORM_FIELD_ID_PREFIX + self.field_name, self.__class__.__name__, self.is_required and ' required' or '', 312 self.field_name, self.size)]316 hasattr(self, 'db_field_name') and self.db_field_name or self.field_name, self.size)] 313 317 str_data = str(data) # normalize to string 314 318 for value, display_name in self.choices: 315 319 selected_html = '' -
django/core/meta/fields.py
188 188 else: 189 189 field_objs = [formfields.SelectField] 190 190 params['choices'] = self.get_choices() 191 params['db_field_name'] = self.get_db_column() 191 192 elif self.choices: 192 193 if self.radio_admin: 193 194 field_objs = [formfields.RadioSelectField]