Ticket #570: 570.2.diff

File 570.2.diff, 2.3 KB (added by Maniac <Maniac@…>, 19 years ago)

corrected patch, added '_id' to <select> names

  • django/core/formfields.py

     
    116116            if field.field_name == key:
    117117                if hasattr(field, 'requires_data_list') and hasattr(self.data, 'getlist'):
    118118                    data = self.data.getlist(field.field_name)
     119                elif hasattr(field, 'db_field_name'):
     120                    data = self.data.get(field.db_field_name, None)
    119121                else:
    120122                    data = self.data.get(field.field_name, None)
    121123                if data is None:
     
    300302    html2python = staticmethod(html2python)
    301303
    302304class 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=[]):
    304306        self.field_name = field_name
     307        if db_field_name:
     308            self.db_field_name = db_field_name
    305309        # choices is a list of (value, human-readable key) tuples because order matters
    306310        self.choices, self.size, self.is_required = choices, size, is_required
    307311        self.validator_list = [self.isValidChoice] + validator_list
     
    309313    def render(self, data):
    310314        output = ['<select id="%s" class="v%s%s" name="%s" size="%s">' % \
    311315            (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)]
    313317        str_data = str(data) # normalize to string
    314318        for value, display_name in self.choices:
    315319            selected_html = ''
  • django/core/meta/fields.py

     
    188188                    else:
    189189                        field_objs = [formfields.SelectField]
    190190                    params['choices'] = self.get_choices()
     191                    params['db_field_name'] = self.get_db_column()
    191192        elif self.choices:
    192193            if self.radio_admin:
    193194                field_objs = [formfields.RadioSelectField]
Back to Top