Ticket #5247: test_patch_ticket5247_r11751.diff

File test_patch_ticket5247_r11751.diff, 1.7 KB (added by Tim Kersten, 15 years ago)
  • tests/regressiontests/forms/models.py

     
    131131>>> list(ChoiceFieldForm().fields['choice'].choices)
    132132[(1, u'ChoiceOptionModel object')]
    133133
     134# Test CheckboxSelectMultiple with a list of models as the initial value #####################
     135>>> w = django_forms.widgets.CheckboxSelectMultiple()
     136>>> john = ChoiceModel(id=20001, name="John")
     137>>> john.save()
     138>>> paul = ChoiceModel(id=20002, name="Paul")
     139>>> paul.save()
     140>>> choices=((john.pk, john.name), (paul.pk, paul.name))
     141>>> print w.render('beatles', [john], choices=choices)
     142<ul>
     143<li><label><input checked="checked" type="checkbox" name="beatles" value="20001" /> John</label></li>
     144<li><label><input type="checkbox" name="beatles" value="20002" /> Paul</label></li>
     145</ul>
     146>>> print w.render('beatles', [paul], choices=choices)
     147<ul>
     148<li><label><input type="checkbox" name="beatles" value="20001" /> John</label></li>
     149<li><label><input checked="checked" type="checkbox" name="beatles" value="20002" /> Paul</label></li>
     150</ul>
     151>>> print w.render('beatles', [john, paul], choices=choices)
     152<ul>
     153<li><label><input checked="checked" type="checkbox" name="beatles" value="20001" /> John</label></li>
     154<li><label><input checked="checked" type="checkbox" name="beatles" value="20002" /> Paul</label></li>
     155</ul>
     156>>> print w.render('beatles', None, choices=choices)
     157<ul>
     158<li><label><input type="checkbox" name="beatles" value="20001" /> John</label></li>
     159<li><label><input type="checkbox" name="beatles" value="20002" /> Paul</label></li>
     160</ul>
    134161"""}
Back to Top