| 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> |