Skip to content

Commit

Permalink
Tweaked the model_formsets test to work around a weird sorting proble…
Browse files Browse the repository at this point in the history
…m 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
  • Loading branch information
freakboy3742 committed Dec 22, 2009
1 parent ff60c5f commit d9568af
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tests/modeltests/model_formsets/models.py
Expand Up @@ -512,7 +512,7 @@ def __unicode__(self):
... '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': '',
... }
Expand All @@ -521,14 +521,14 @@ def __unicode__(self):
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.
Expand All @@ -539,7 +539,7 @@ def __unicode__(self):
... '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': '',
... }
Expand All @@ -550,7 +550,7 @@ def __unicode__(self):
>>> 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.
Expand Down Expand Up @@ -650,8 +650,8 @@ def __unicode__(self):
>>> 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>
Expand All @@ -662,7 +662,7 @@ def __unicode__(self):
... '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',
Expand Down

0 comments on commit d9568af

Please sign in to comment.