summaryrefslogtreecommitdiff
path: root/tests/modeltests/model_forms
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-01-28 22:26:25 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-01-28 22:26:25 +0000
commit8b837ba33dcaa6497ed9a7ffe7466dddb3af0e73 (patch)
treefd9b6a2b968c5ffe4d9f98a9f7538d85c8b82e15 /tests/modeltests/model_forms
parent4d829c2e0e2589080096354f7d2e4e8c4fb7657c (diff)
newforms-admin: Merged to [4440]
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@4441 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests/model_forms')
-rw-r--r--tests/modeltests/model_forms/models.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py
index 620565721c..81a7ec2abf 100644
--- a/tests/modeltests/model_forms/models.py
+++ b/tests/modeltests/model_forms/models.py
@@ -224,6 +224,47 @@ Add some categories and test the many-to-many form output.
<option value="3">Third test</option>
</select></li>
+>>> f = TestArticleForm({'headline': u'New headline', 'pub_date': u'1988-01-04',
+... 'writer': u'1', 'article': u'Hello.', 'categories': [u'1', u'2']})
+>>> new_art = f.save()
+>>> new_art.id
+1
+>>> new_art = Article.objects.get(id=1)
+>>> new_art.categories.all()
+[<Category: Entertainment>, <Category: It's a test>]
+
+Now, submit form data with no categories. This deletes the existing categories.
+>>> f = TestArticleForm({'headline': u'New headline', 'pub_date': u'1988-01-04',
+... 'writer': u'1', 'article': u'Hello.'})
+>>> new_art = f.save()
+>>> new_art.id
+1
+>>> new_art = Article.objects.get(id=1)
+>>> new_art.categories.all()
+[]
+
+Create a new article, with categories, via the form.
+>>> ArticleForm = form_for_model(Article)
+>>> f = ArticleForm({'headline': u'The walrus was Paul', 'pub_date': u'1967-11-01',
+... 'writer': u'1', 'article': u'Test.', 'categories': [u'1', u'2']})
+>>> new_art = f.save()
+>>> new_art.id
+2
+>>> new_art = Article.objects.get(id=2)
+>>> new_art.categories.all()
+[<Category: Entertainment>, <Category: It's a test>]
+
+Create a new article, with no categories, via the form.
+>>> ArticleForm = form_for_model(Article)
+>>> f = ArticleForm({'headline': u'The walrus was Paul', 'pub_date': u'1967-11-01',
+... 'writer': u'1', 'article': u'Test.'})
+>>> new_art = f.save()
+>>> new_art.id
+3
+>>> new_art = Article.objects.get(id=3)
+>>> new_art.categories.all()
+[]
+
Here, we define a custom Form. Because it happens to have the same fields as
the Category model, we can use save_instance() to apply its changes to an
existing Category instance.