summaryrefslogtreecommitdiff
path: root/tests/modeltests
diff options
context:
space:
mode:
authorJason Pellerin <jpellerin@gmail.com>2006-11-29 20:16:50 +0000
committerJason Pellerin <jpellerin@gmail.com>2006-11-29 20:16:50 +0000
commitf8217026f9618adb65ab2d517025e87b98ed2fbe (patch)
tree2ab846582343dc9b0894b0bdffa3fe04f590365b /tests/modeltests
parent9a01534370a272e59f2bb64251d1f46218a32516 (diff)
[multi-db] Merge trunk to [3850]. Some tests still failing.
git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@4142 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests')
-rw-r--r--tests/modeltests/basic/models.py4
-rw-r--r--tests/modeltests/custom_pk/models.py4
-rw-r--r--tests/modeltests/one_to_one/models.py14
3 files changed, 22 insertions, 0 deletions
diff --git a/tests/modeltests/basic/models.py b/tests/modeltests/basic/models.py
index acbea0d1e0..5638865f31 100644
--- a/tests/modeltests/basic/models.py
+++ b/tests/modeltests/basic/models.py
@@ -86,6 +86,10 @@ DoesNotExist: Article matching query does not exist.
>>> Article.objects.get(pk=1)
<Article: Area woman programs in Python>
+# pk can be used as a shortcut for the primary key name in any query
+>>> Article.objects.filter(pk__in=[1])
+[<Article: Area woman programs in Python>]
+
# Model instances of the same type and same ID are considered equal.
>>> a = Article.objects.get(pk=1)
>>> b = Article.objects.get(pk=1)
diff --git a/tests/modeltests/custom_pk/models.py b/tests/modeltests/custom_pk/models.py
index ca788f6aa5..fd0901da3c 100644
--- a/tests/modeltests/custom_pk/models.py
+++ b/tests/modeltests/custom_pk/models.py
@@ -51,6 +51,10 @@ DoesNotExist: Employee matching query does not exist.
>>> Employee.objects.get(employee_code__exact='ABC123')
<Employee: Dan Jones>
+# pk can be used as a substitute for the primary key.
+>>> Employee.objects.filter(pk__in=['ABC123','XYZ456'])
+[<Employee: Fran Bones>, <Employee: Dan Jones>]
+
# Fran got married and changed her last name.
>>> fran = Employee.objects.get(pk='XYZ456')
>>> fran.last_name = 'Jones'
diff --git a/tests/modeltests/one_to_one/models.py b/tests/modeltests/one_to_one/models.py
index 8afa74454d..7488204ff1 100644
--- a/tests/modeltests/one_to_one/models.py
+++ b/tests/modeltests/one_to_one/models.py
@@ -30,6 +30,14 @@ class Waiter(models.Model):
def __str__(self):
return "%s the waiter at %s" % (self.name, self.restaurant)
+class ManualPrimaryKey(models.Model):
+ primary_key = models.CharField(maxlength=10, primary_key=True)
+ name = models.CharField(maxlength = 50)
+
+class RelatedModel(models.Model):
+ link = models.OneToOneField(ManualPrimaryKey)
+ name = models.CharField(maxlength = 50)
+
__test__ = {'API_TESTS':"""
# Create a couple of Places.
>>> p1 = Place(name='Demon Dogs', address='944 W. Fullerton')
@@ -151,4 +159,10 @@ DoesNotExist: Restaurant matching query does not exist.
# Delete the restaurant; the waiter should also be removed
>>> r = Restaurant.objects.get(pk=1)
>>> r.delete()
+
+# One-to-one fields still work if you create your own primary key
+>>> o1 = ManualPrimaryKey(primary_key="abc123", name="primary")
+>>> o1.save()
+>>> o2 = RelatedModel(link=o1, name="secondary")
+>>> o2.save()
"""}