Code

Ticket #570: 570.2.diff

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

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

Line 
1Index: django/core/formfields.py
2===================================================================
3--- django/core/formfields.py   (revision 687)
4+++ django/core/formfields.py   (working copy)
5@@ -116,6 +116,8 @@
6             if field.field_name == key:
7                 if hasattr(field, 'requires_data_list') and hasattr(self.data, 'getlist'):
8                     data = self.data.getlist(field.field_name)
9+                elif hasattr(field, 'db_field_name'):
10+                    data = self.data.get(field.db_field_name, None)
11                 else:
12                     data = self.data.get(field.field_name, None)
13                 if data is None:
14@@ -300,8 +302,10 @@
15     html2python = staticmethod(html2python)
16 
17 class SelectField(FormField):
18-    def __init__(self, field_name, choices=[], size=1, is_required=False, validator_list=[]):
19+    def __init__(self, field_name, db_field_name=None, choices=[], size=1, is_required=False, validator_list=[]):
20         self.field_name = field_name
21+        if db_field_name:
22+            self.db_field_name = db_field_name
23         # choices is a list of (value, human-readable key) tuples because order matters
24         self.choices, self.size, self.is_required = choices, size, is_required
25         self.validator_list = [self.isValidChoice] + validator_list
26@@ -309,7 +313,7 @@
27     def render(self, data):
28         output = ['<select id="%s" class="v%s%s" name="%s" size="%s">' % \
29             (FORM_FIELD_ID_PREFIX + self.field_name, self.__class__.__name__, self.is_required and ' required' or '',
30-            self.field_name, self.size)]
31+            hasattr(self, 'db_field_name') and self.db_field_name or self.field_name, self.size)]
32         str_data = str(data) # normalize to string
33         for value, display_name in self.choices:
34             selected_html = ''
35Index: django/core/meta/fields.py
36===================================================================
37--- django/core/meta/fields.py  (revision 687)
38+++ django/core/meta/fields.py  (working copy)
39@@ -188,6 +188,7 @@
40                     else:
41                         field_objs = [formfields.SelectField]
42                     params['choices'] = self.get_choices()
43+                    params['db_field_name'] = self.get_db_column()
44         elif self.choices:
45             if self.radio_admin:
46                 field_objs = [formfields.RadioSelectField]