mirror of
https://github.com/django/django.git
synced 2025-04-25 17:54:37 +00:00
Fixed #24881 -- Clarified Meta.order_with_respect_to documentation
This commit is contained in:
parent
0d97e73d95
commit
27c839e0fc
@ -173,11 +173,11 @@ Django quotes column and table names behind the scenes.
|
|||||||
|
|
||||||
.. attribute:: Options.order_with_respect_to
|
.. attribute:: Options.order_with_respect_to
|
||||||
|
|
||||||
Marks this object as "orderable" with respect to the given field. This is almost
|
Makes this object orderable with respect to the given field, usually a
|
||||||
always used with related objects to allow them to be ordered with respect to a
|
``ForeignKey``. This can be used to make related objects orderable with
|
||||||
parent object. For example, if an ``Answer`` relates to a ``Question`` object,
|
respect to a parent object. For example, if an ``Answer`` relates to a
|
||||||
and a question has more than one answer, and the order of answers matters, you'd
|
``Question`` object, and a question has more than one answer, and the order
|
||||||
do this::
|
of answers matters, you'd do this::
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
@ -218,12 +218,20 @@ Django quotes column and table names behind the scenes.
|
|||||||
>>> answer.get_previous_in_order()
|
>>> answer.get_previous_in_order()
|
||||||
<Answer: 1>
|
<Answer: 1>
|
||||||
|
|
||||||
.. admonition:: Changing order_with_respect_to
|
.. admonition:: ``order_with_respect_to`` implicitly sets the ``ordering`` option
|
||||||
|
|
||||||
``order_with_respect_to`` adds an additional field/database column
|
Internally, ``order_with_respect_to`` adds an additional field/database
|
||||||
named ``_order``, so be sure to make and apply the appropriate
|
column named ``_order`` and sets the model's :attr:`~Options.ordering`
|
||||||
migrations if you add or change ``order_with_respect_to``
|
option to this field. Consequently, ``order_with_respect_to`` and
|
||||||
after your initial :djadmin:`migrate`.
|
``ordering`` cannot be used together, and the ordering added by
|
||||||
|
``order_with_respect_to`` will apply whenever you obtain a list of objects
|
||||||
|
of this model.
|
||||||
|
|
||||||
|
.. admonition:: Changing ``order_with_respect_to``
|
||||||
|
|
||||||
|
Because ``order_with_respect_to`` adds a new database column, be sure to
|
||||||
|
make and apply the appropriate migrations if you add or change
|
||||||
|
``order_with_respect_to`` after your initial :djadmin:`migrate`.
|
||||||
|
|
||||||
``ordering``
|
``ordering``
|
||||||
------------
|
------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user