| 435 | # FormSets with ordering + deletion and internationalization ################## |
| 436 | |
| 437 | >>> from django.utils.translation import activate, deactivate |
| 438 | >>> ChoiceFormSet = formset_factory(Choice, can_order=True, can_delete=True) |
| 439 | |
| 440 | >>> initial = [ |
| 441 | ... {'choice': u'Calexico', 'votes': 100}, |
| 442 | ... {'choice': u'Fergie', 'votes': 900}, |
| 443 | ... {'choice': u'The Decemberists', 'votes': 500}, |
| 444 | ... ] |
| 445 | >>> formset = ChoiceFormSet(initial=initial, auto_id=False, prefix='choices') |
| 446 | >>> for form in formset.forms: |
| 447 | ... print form.as_ul() |
| 448 | <li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> |
| 449 | <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li> |
| 450 | <li>Order: <input type="text" name="choices-0-ORDER" value="1" /></li> |
| 451 | <li>Delete: <input type="checkbox" name="choices-0-DELETE" /></li> |
| 452 | <li>Choice: <input type="text" name="choices-1-choice" value="Fergie" /></li> |
| 453 | <li>Votes: <input type="text" name="choices-1-votes" value="900" /></li> |
| 454 | <li>Order: <input type="text" name="choices-1-ORDER" value="2" /></li> |
| 455 | <li>Delete: <input type="checkbox" name="choices-1-DELETE" /></li> |
| 456 | <li>Choice: <input type="text" name="choices-2-choice" value="The Decemberists" /></li> |
| 457 | <li>Votes: <input type="text" name="choices-2-votes" value="500" /></li> |
| 458 | <li>Order: <input type="text" name="choices-2-ORDER" value="3" /></li> |
| 459 | <li>Delete: <input type="checkbox" name="choices-2-DELETE" /></li> |
| 460 | <li>Choice: <input type="text" name="choices-3-choice" /></li> |
| 461 | <li>Votes: <input type="text" name="choices-3-votes" /></li> |
| 462 | <li>Order: <input type="text" name="choices-3-ORDER" /></li> |
| 463 | <li>Delete: <input type="checkbox" name="choices-3-DELETE" /></li> |
| 464 | |
| 465 | >>> activate('es') |
| 466 | >>> for form in formset.forms: |
| 467 | ... print form.as_ul() |
| 468 | <li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> |
| 469 | <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li> |
| 470 | <li>Orden: <input type="text" name="choices-0-ORDER" value="1" /></li> |
| 471 | <li>Eliminar: <input type="checkbox" name="choices-0-DELETE" /></li> |
| 472 | <li>Choice: <input type="text" name="choices-1-choice" value="Fergie" /></li> |
| 473 | <li>Votes: <input type="text" name="choices-1-votes" value="900" /></li> |
| 474 | <li>Orden: <input type="text" name="choices-1-ORDER" value="2" /></li> |
| 475 | <li>Eliminar: <input type="checkbox" name="choices-1-DELETE" /></li> |
| 476 | <li>Choice: <input type="text" name="choices-2-choice" value="The Decemberists" /></li> |
| 477 | <li>Votes: <input type="text" name="choices-2-votes" value="500" /></li> |
| 478 | <li>Orden: <input type="text" name="choices-2-ORDER" value="3" /></li> |
| 479 | <li>Eliminar: <input type="checkbox" name="choices-2-DELETE" /></li> |
| 480 | <li>Choice: <input type="text" name="choices-3-choice" /></li> |
| 481 | <li>Votes: <input type="text" name="choices-3-votes" /></li> |
| 482 | <li>Orden: <input type="text" name="choices-3-ORDER" /></li> |
| 483 | <li>Eliminar: <input type="checkbox" name="choices-3-DELETE" /></li> |
| 484 | >>> deactivate() |
| 485 | |