Ticket #5247: multipatch.patch
File multipatch.patch, 2.4 KB (added by , 17 years ago) |
---|
-
django/newforms/models.py
7 7 from util import ValidationError 8 8 from forms import BaseForm, DeclarativeFieldsMetaclass, SortedDictFromList 9 9 from fields import Field, ChoiceField 10 from widgets import Select, SelectMultiple, MultipleHiddenInput 10 from widgets import Select, SelectMultiple, MultipleHiddenInput, ModelSelectMultiple 11 11 12 12 __all__ = ('save_instance', 'form_for_model', 'form_for_instance', 'form_for_fields', 13 13 'ModelChoiceField', 'ModelMultipleChoiceField') … … 168 168 "A MultipleChoiceField whose choices are a model QuerySet." 169 169 hidden_widget = MultipleHiddenInput 170 170 def __init__(self, queryset, cache_choices=False, required=True, 171 widget= SelectMultiple, label=None, initial=None, help_text=None):171 widget=ModelSelectMultiple, label=None, initial=None, help_text=None): 172 172 super(ModelMultipleChoiceField, self).__init__(queryset, None, cache_choices, 173 173 required, widget, label, initial, help_text) 174 174 -
django/newforms/widgets.py
191 191 if value is None: value = [] 192 192 final_attrs = self.build_attrs(attrs, name=name) 193 193 output = [u'<select multiple="multiple"%s>' % flatatt(final_attrs)] 194 str_values = set([s mart_unicode(v) for v in value]) # Normalize to strings.194 str_values = set([self.value_to_str(v) for v in value]) # Normalize to strings. 195 195 for option_value, option_label in chain(self.choices, choices): 196 196 option_value = smart_unicode(option_value) 197 197 selected_html = (option_value in str_values) and ' selected="selected"' or '' … … 204 204 return data.getlist(name) 205 205 return data.get(name, None) 206 206 207 def value_to_str(cls, value): 208 return smart_unicode(value) 209 210 def ModelSelectMultiple(forms.SelectMultiple): 211 def value_to_str(cls, value): 212 return super(ModelSelectMultiple, cls).value_to_str(value._get_pk_val()) 213 207 214 class RadioInput(StrAndUnicode): 208 215 "An object used by RadioFieldRenderer that represents a single <input type='radio'>." 209 216 def __init__(self, name, value, attrs, choice, index):