Ticket #5247: patch_ticket5247_r11751.diff

File patch_ticket5247_r11751.diff, 922 bytes (added by Tim Kersten, 13 years ago)
  • django/forms/widgets.py

     
    579579        final_attrs = self.build_attrs(attrs, name=name)
    580580        output = [u'<ul>']
    581581        # Normalize to strings
    582         str_values = set([force_unicode(v) for v in value])
     582        use_pk = value and hasattr(value[0], 'pk')
     583        if use_pk:
     584            # Assume we are using models if it's got a 'pk' attribute.
     585            str_values = set([force_unicode(v.pk) for v in value])
     586        else:
     587            str_values = set([force_unicode(v) for v in value])
    583588        for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
    584589            # If an ID attribute was given, add a numeric index as a suffix,
    585590            # so that the checkboxes don't all have the same ID attribute.
Back to Top