Tweaked the model_formsets test to work around a weird sorting problem between versions of Postgres. Thanks to Alex Gaynor for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11953 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ff60c5f9de
commit
d9568af974
|
@ -512,7 +512,7 @@ book.
|
|||
... 'book_set-INITIAL_FORMS': '1', # the number of forms with initial data
|
||||
... 'book_set-0-id': '1',
|
||||
... 'book_set-0-title': 'Les Fleurs du Mal',
|
||||
... 'book_set-1-title': 'Le Spleen de Paris',
|
||||
... 'book_set-1-title': 'Les Paradis Artificiels',
|
||||
... 'book_set-2-title': '',
|
||||
... }
|
||||
|
||||
|
@ -521,14 +521,14 @@ book.
|
|||
True
|
||||
|
||||
>>> formset.save()
|
||||
[<Book: Le Spleen de Paris>]
|
||||
[<Book: Les Paradis Artificiels>]
|
||||
|
||||
As you can see, 'Le Spleen de Paris' is now a book belonging to Charles Baudelaire.
|
||||
As you can see, 'Les Paradis Artificiels' is now a book belonging to Charles Baudelaire.
|
||||
|
||||
>>> for book in author.book_set.order_by('id'):
|
||||
... print book.title
|
||||
Les Fleurs du Mal
|
||||
Le Spleen de Paris
|
||||
Les Paradis Artificiels
|
||||
|
||||
The save_as_new parameter lets you re-associate the data to a new instance.
|
||||
This is used in the admin for save_as functionality.
|
||||
|
@ -539,7 +539,7 @@ This is used in the admin for save_as functionality.
|
|||
... 'book_set-0-id': '1',
|
||||
... 'book_set-0-title': 'Les Fleurs du Mal',
|
||||
... 'book_set-1-id': '2',
|
||||
... 'book_set-1-title': 'Le Spleen de Paris',
|
||||
... 'book_set-1-title': 'Les Paradis Artificiels',
|
||||
... 'book_set-2-title': '',
|
||||
... }
|
||||
|
||||
|
@ -550,7 +550,7 @@ True
|
|||
>>> new_author = Author.objects.create(name='Charles Baudelaire')
|
||||
>>> formset = AuthorBooksFormSet(data, instance=new_author, save_as_new=True)
|
||||
>>> [book for book in formset.save() if book.author.pk == new_author.pk]
|
||||
[<Book: Les Fleurs du Mal>, <Book: Le Spleen de Paris>]
|
||||
[<Book: Les Fleurs du Mal>, <Book: Les Paradis Artificiels>]
|
||||
|
||||
Test using a custom prefix on an inline formset.
|
||||
|
||||
|
@ -650,8 +650,8 @@ We can provide a custom queryset to our InlineFormSet:
|
|||
>>> formset = AuthorBooksFormSet(instance=author, queryset=custom_qs)
|
||||
>>> for form in formset.forms:
|
||||
... print form.as_p()
|
||||
<p><label for="id_book_set-0-title">Title:</label> <input id="id_book_set-0-title" type="text" name="book_set-0-title" value="Les Fleurs du Mal" maxlength="100" /><input type="hidden" name="book_set-0-author" value="1" id="id_book_set-0-author" /><input type="hidden" name="book_set-0-id" value="1" id="id_book_set-0-id" /></p>
|
||||
<p><label for="id_book_set-1-title">Title:</label> <input id="id_book_set-1-title" type="text" name="book_set-1-title" value="Le Spleen de Paris" maxlength="100" /><input type="hidden" name="book_set-1-author" value="1" id="id_book_set-1-author" /><input type="hidden" name="book_set-1-id" value="2" id="id_book_set-1-id" /></p>
|
||||
<p><label for="id_book_set-0-title">Title:</label> <input id="id_book_set-0-title" type="text" name="book_set-0-title" value="Les Paradis Artificiels" maxlength="100" /><input type="hidden" name="book_set-0-author" value="1" id="id_book_set-0-author" /><input type="hidden" name="book_set-0-id" value="2" id="id_book_set-0-id" /></p>
|
||||
<p><label for="id_book_set-1-title">Title:</label> <input id="id_book_set-1-title" type="text" name="book_set-1-title" value="Les Fleurs du Mal" maxlength="100" /><input type="hidden" name="book_set-1-author" value="1" id="id_book_set-1-author" /><input type="hidden" name="book_set-1-id" value="1" id="id_book_set-1-id" /></p>
|
||||
<p><label for="id_book_set-2-title">Title:</label> <input id="id_book_set-2-title" type="text" name="book_set-2-title" value="Flowers of Evil" maxlength="100" /><input type="hidden" name="book_set-2-author" value="1" id="id_book_set-2-author" /><input type="hidden" name="book_set-2-id" value="5" id="id_book_set-2-id" /></p>
|
||||
<p><label for="id_book_set-3-title">Title:</label> <input id="id_book_set-3-title" type="text" name="book_set-3-title" maxlength="100" /><input type="hidden" name="book_set-3-author" value="1" id="id_book_set-3-author" /><input type="hidden" name="book_set-3-id" id="id_book_set-3-id" /></p>
|
||||
<p><label for="id_book_set-4-title">Title:</label> <input id="id_book_set-4-title" type="text" name="book_set-4-title" maxlength="100" /><input type="hidden" name="book_set-4-author" value="1" id="id_book_set-4-author" /><input type="hidden" name="book_set-4-id" id="id_book_set-4-id" /></p>
|
||||
|
@ -662,7 +662,7 @@ We can provide a custom queryset to our InlineFormSet:
|
|||
... 'book_set-0-id': '1',
|
||||
... 'book_set-0-title': 'Les Fleurs du Mal',
|
||||
... 'book_set-1-id': '2',
|
||||
... 'book_set-1-title': 'Le Spleen de Paris',
|
||||
... 'book_set-1-title': 'Les Paradis Artificiels',
|
||||
... 'book_set-2-id': '5',
|
||||
... 'book_set-2-title': 'Flowers of Evil',
|
||||
... 'book_set-3-title': 'Revue des deux mondes',
|
||||
|
|
Loading…
Reference in New Issue