| 586 | |
| 587 | # form_for_* blank choices #################################################### |
| 588 | |
| 589 | Show the form for a new Car. Note that steering field doesn't include the blank choice, |
| 590 | because the field is obligatory and has an explicit default. |
| 591 | >>> CarForm = form_for_model(Car) |
| 592 | >>> f = CarForm(auto_id=False) |
| 593 | >>> print f |
| 594 | <tr><th>Name:</th><td><input type="text" name="name" maxlength="50" /></td></tr> |
| 595 | <tr><th>Steering:</th><td><select name="steering"> |
| 596 | <option value="left" selected="selected">Left steering wheel</option> |
| 597 | <option value="right">Right steering wheel</option> |
| 598 | </select></td></tr> |
| 599 | <tr><th>Fuel:</th><td><select name="fuel"> |
| 600 | <option value="" selected="selected">---------</option> |
| 601 | <option value="gas">Gasoline</option> |
| 602 | <option value="diesel">Diesel</option> |
| 603 | <option value="other">Other</option> |
| 604 | </select></td></tr> |
| 605 | <tr><th>Transmission:</th><td><select name="transmission"> |
| 606 | <option value="" selected="selected">---------</option> |
| 607 | <option value="at">Automatic</option> |
| 608 | <option value="mt">Manual</option> |
| 609 | <option value="cvt">CVT</option> |
| 610 | </select><br />Leave empty if not applicable.</td></tr> |
| 611 | |
| 612 | Create a Car, and display the form for modifying it. Note that now the fuel |
| 613 | selector doesn't include the blank choice as well, since the field is |
| 614 | obligatory and can not be changed to be blank. |
| 615 | >>> honda = Car(name='Honda Accord Wagon', steering='right', fuel='gas', transmission='at') |
| 616 | >>> honda.save() |
| 617 | >>> HondaForm = form_for_instance(honda) |
| 618 | >>> f = HondaForm(auto_id=False) |
| 619 | >>> print f |
| 620 | <tr><th>Name:</th><td><input type="text" name="name" value="Honda Accord Wagon" maxlength="50" /></td></tr> |
| 621 | <tr><th>Steering:</th><td><select name="steering"> |
| 622 | <option value="left">Left steering wheel</option> |
| 623 | <option value="right" selected="selected">Right steering wheel</option> |
| 624 | </select></td></tr> |
| 625 | <tr><th>Fuel:</th><td><select name="fuel"> |
| 626 | <option value="gas" selected="selected">Gasoline</option> |
| 627 | <option value="diesel">Diesel</option> |
| 628 | <option value="other">Other</option> |
| 629 | </select></td></tr> |
| 630 | <tr><th>Transmission:</th><td><select name="transmission"> |
| 631 | <option value="">---------</option> |
| 632 | <option value="at" selected="selected">Automatic</option> |
| 633 | <option value="mt">Manual</option> |
| 634 | <option value="cvt">CVT</option> |
| 635 | </select><br />Leave empty if not applicable.</td></tr> |