浏览代码

Refs #36070 -- Referred to pk as an attribute when a composite primary key is defined.

This is to avoid confusion that a field is often associated with having
a single associated database column.
Jacob Walls 2 月之前
父节点
当前提交
f054045973
共有 4 个文件被更改,包括 16 次插入11 次删除
  1. 2 2
      docs/ref/models/fields.txt
  2. 8 3
      docs/ref/models/instances.txt
  3. 2 2
      docs/releases/5.2.txt
  4. 4 4
      docs/topics/composite-primary-key.txt

+ 2 - 2
docs/ref/models/fields.txt

@@ -722,8 +722,8 @@ isn't defined.
 
 A virtual field used for defining a composite primary key.
 
-This field must be defined as the model's ``pk`` field. If present, Django will
-create the underlying model table with a composite primary key.
+This field must be defined as the model's ``pk`` attribute. If present, Django
+will create the underlying model table with a composite primary key.
 
 The ``*field_names`` argument is a list of positional field names that compose
 the primary key.

+ 8 - 3
docs/ref/models/instances.txt

@@ -468,9 +468,14 @@ The ``pk`` property
 Regardless of whether you define a primary key field yourself, or let Django
 supply one for you, each model will have a property called ``pk``. It behaves
 like a normal attribute on the model, but is actually an alias for whichever
-attribute is the primary key field for the model. You can read and set this
-value, just as you would for any other attribute, and it will update the
-correct field in the model.
+field or fields compose the primary key for the model. You can read and set
+this value, just as you would for any other attribute, and it will update the
+correct fields in the model.
+
+.. versionchanged:: 5.2
+
+    Support for the primary key to be composed of multiple fields was added via
+    ``CompositePrimaryKey``.
 
 Explicitly specifying auto-primary-key values
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 2 - 2
docs/releases/5.2.txt

@@ -57,8 +57,8 @@ Composite Primary Keys
 The new :class:`django.db.models.CompositePrimaryKey` allows tables to be
 created with a primary key consisting of multiple fields.
 
-To use a composite primary key, when creating a model set the ``pk`` field to
-be a ``CompositePrimaryKey``::
+To use a composite primary key, when defining a model set the ``pk`` attribute
+to be a ``CompositePrimaryKey``::
 
     from django.db import models
 

+ 4 - 4
docs/topics/composite-primary-key.txt

@@ -11,8 +11,8 @@ In most cases, a single primary key should suffice. In database design,
 however, defining a primary key consisting of multiple fields is sometimes
 necessary.
 
-To use a composite primary key, when creating a model set the ``pk`` field to
-be a :class:`.CompositePrimaryKey`::
+To use a composite primary key, when defining a model set the ``pk`` attribute
+to be a :class:`.CompositePrimaryKey`::
 
     class Product(models.Model):
         name = models.CharField(max_length=100)
@@ -41,8 +41,8 @@ A composite primary key is represented by a ``tuple``:
     >>> item.pk
     (1, "A755H")
 
-You can assign a ``tuple`` to a composite primary key. This sets the associated
-field values.
+You can assign a ``tuple`` to the :attr:`~django.db.models.Model.pk` attribute.
+This sets the associated field values:
 
 .. code-block:: pycon