summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2011-01-08 13:27:30 +0000
committerAndrew Godwin <andrew@aeracode.org>2011-01-08 13:27:30 +0000
commit81e05a418dc6f347d9627373288e773c477a9fe0 (patch)
treeb141cbd00a53b425d28ded7cd1ae6e6b7b5021d4 /tests
parent32a344dfe297a16087765d2f4fb2e1398dc21ac8 (diff)
Fixed #9029 -- Allow use of fieldname_id with get_or_create. Thanks to aaron and mrmachine.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15156 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/get_or_create_regress/tests.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/tests/regressiontests/get_or_create_regress/tests.py b/tests/regressiontests/get_or_create_regress/tests.py
index 87057dab3f..e825fccc4b 100644
--- a/tests/regressiontests/get_or_create_regress/tests.py
+++ b/tests/regressiontests/get_or_create_regress/tests.py
@@ -21,7 +21,7 @@ class GetOrCreateTests(TestCase):
# Add an author to the book.
ed, created = book.authors.get_or_create(name="Ed")
self.assertTrue(created)
- # Book should have one author.
+ # The book should have one author.
self.assertEqual(book.authors.count(), 1)
# Try get_or_create again, this time nothing should be created.
@@ -51,3 +51,12 @@ class GetOrCreateTests(TestCase):
# Now Ed has two Books, Fred just one.
self.assertEqual(ed.books.count(), 2)
self.assertEqual(fred.books.count(), 1)
+
+ # Use the publisher's primary key value instead of a model instance.
+ _, created = ed.books.get_or_create(name='The Great Book of Ed', publisher_id=p.id)
+ self.assertTrue(created)
+ # Try get_or_create again, this time nothing should be created.
+ _, created = ed.books.get_or_create(name='The Great Book of Ed', publisher_id=p.id)
+ self.assertFalse(created)
+ # The publisher should have three books.
+ self.assertEqual(p.books.count(), 3)