diff options
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' |
