| 529 | Test inline formsets where the inline-edited object uses multi-table inheritance, thus |
| 530 | has a non AutoField yet auto-created primary key. |
| 531 | |
| 532 | >>> AuthorBooksFormSet3 = inlineformset_factory(Author, AlternateBook, can_delete=False, extra=1) |
| 533 | |
| 534 | >>> formset = AuthorBooksFormSet3(instance=author) |
| 535 | >>> for form in formset.forms: |
| 536 | ... print form.as_p() |
| 537 | <p><label for="id_alternatebook_set-0-title">Title:</label> <input id="id_alternatebook_set-0-title" type="text" name="alternatebook_set-0-title" maxlength="100" /></p> |
| 538 | <p><label for="id_alternatebook_set-0-notes">Notes:</label> <input id="id_alternatebook_set-0-notes" type="text" name="alternatebook_set-0-notes" maxlength="100" /><input type="hidden" name="alternatebook_set-0-author" value="1" id="id_alternatebook_set-0-author" /><input type="hidden" name="alternatebook_set-0-book_ptr" id="id_alternatebook_set-0-book_ptr" /></p> |
| 539 | |
| 540 | |
| 541 | >>> data = { |
| 542 | ... 'alternatebook_set-TOTAL_FORMS': '1', # the number of forms rendered |
| 543 | ... 'alternatebook_set-INITIAL_FORMS': '0', # the number of forms with initial data |
| 544 | ... 'alternatebook_set-0-title': 'Flowers of Evil', |
| 545 | ... 'alternatebook_set-0-notes': 'English translation of Les Fleurs du Mal' |
| 546 | ... } |
| 547 | |
| 548 | >>> formset = AuthorBooksFormSet3(data, instance=author) |
| 549 | >>> formset.is_valid() |
| 550 | True |
| 551 | |
| 552 | >>> formset.save() |
| 553 | [<AlternateBook: Flowers of Evil - English translation of Les Fleurs du Mal>] |
| 554 | |
| 555 | |