diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2006-09-25 13:49:01 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2006-09-25 13:49:01 +0000 |
| commit | 0c41869e6ccf779e19032dede71a627c4370b68a (patch) | |
| tree | 06dcb029e3a98afc346c166ce291e6cedf73f936 /tests | |
| parent | f6ec6d24ab0d11b8ce3cdc0fbe6bfab5cee6407e (diff) | |
Made ``pk`` a generic expansion for the primary key, rather than just an expansion for __id__exact.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3826 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/basic/models.py | 4 | ||||
| -rw-r--r-- | tests/modeltests/custom_pk/models.py | 4 |
2 files changed, 8 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' |
