| 512 | |
| 513 | == !ModelForm's constructor now matches Form's == |
| 514 | |
| 515 | {{{instance}}} was moved from the first argument in {{{ModelForm}}}'s {{{__init__}}} method to the last. Also, {{{ModelForm}}} will instantiate a new model object if you don't give it an instance. The model it generates is specified by the {{{ModelForm}}}'s inner {{{Meta}}} classes {{{model}}} attribute. See #6162 for details. |
| 516 | |
| 517 | Before: |
| 518 | {{{ |
| 519 | #!python |
| 520 | # for add forms |
| 521 | obj = MyObj() |
| 522 | form = MyForm(obj) |
| 523 | |
| 524 | # for change forms |
| 525 | obj = MyObj.objects.get(pk=1) |
| 526 | form = MyForm(obj) |
| 527 | }}} |
| 528 | |
| 529 | After: |
| 530 | {{{ |
| 531 | #!python |
| 532 | # for add forms |
| 533 | form = MyForm() |
| 534 | |
| 535 | # for change forms |
| 536 | obj = MyObj.objects.get(pk=1) |
| 537 | form = MyForm(instance=obj) |
| 538 | }}} |