Ticket #5247: patch.diff
File patch.diff, 1.6 KB (added by , 17 years ago) |
---|
-
newforms/widgets.py
250 250 if value is None: value = [] 251 251 final_attrs = self.build_attrs(attrs, name=name) 252 252 output = [u'<select multiple="multiple"%s>' % flatatt(final_attrs)] 253 str_values = set([force_unicode(v) for v in value]) # Normalize to strings. 253 # Normalize to strings 254 str_values = set() 255 for v in value: 256 if hasattr(v, '_get_pk_val'): 257 str_values.add(force_unicode(v._get_pk_val())) 258 else: 259 str_values.add(force_unicode(v)) 254 260 for option_value, option_label in chain(self.choices, choices): 255 261 option_value = force_unicode(option_value) 256 262 selected_html = (option_value in str_values) and ' selected="selected"' or '' … … 352 358 final_attrs = self.build_attrs(attrs, name=name) 353 359 output = [u'<ul>'] 354 360 # Normalize to strings 355 str_values = set([force_unicode(v) for v in value]) 361 str_values = set() 362 for v in value: 363 if hasattr(v, '_get_pk_val'): 364 str_values.add(force_unicode(v._get_pk_val())) 365 else: 366 str_values.add(force_unicode(v)) 356 367 for i, (option_value, option_label) in enumerate(chain(self.choices, choices)): 357 368 # If an ID attribute was given, add a numeric index as a suffix, 358 369 # so that the checkboxes don't all have the same ID attribute.