diff options
| author | Simon Meers <simon@simonmeers.com> | 2010-12-06 23:08:44 +0000 |
|---|---|---|
| committer | Simon Meers <simon@simonmeers.com> | 2010-12-06 23:08:44 +0000 |
| commit | 22fc30be5a54d1027956a9ae668eb24d401483bc (patch) | |
| tree | cbe3d539400602c18b2ea013a2357d20bc032add /docs/ref/models | |
| parent | 4a1fd44c0f19a6d5f7c90cba5c6460f9c4ebc79a (diff) | |
Fixed #8975 -- documented related order methods -- thanks to Leo for the report and dwillis for the initial patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14848 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/ref/models')
| -rw-r--r-- | docs/ref/models/options.txt | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/docs/ref/models/options.txt b/docs/ref/models/options.txt index 3dfcdfffbc..1b04c4698c 100644 --- a/docs/ref/models/options.txt +++ b/docs/ref/models/options.txt @@ -143,6 +143,32 @@ do this:: class Meta: order_with_respect_to = 'question' +When ``order_with_respect_to`` is set, two additional methods are provided to +retrieve and to set the order of the related objects: ``get_RELATED_order()`` +and ``set_RELATED_order()``, where ``RELATED`` is the lowercased model name. For +example, assuming that a ``Question`` object has multiple related ``Answer`` +objects, the list returned contains the primary keys of the related ``Answer`` +objects:: + + >>> question = Question.objects.get(id=1) + >>> question.get_answer_order() + [1, 2, 3] + +The order of a ``Question`` object's related ``Answer`` objects can be set by +passing in a list of ``Answer`` primary keys:: + + >>> question.set_answer_order([3, 1, 2]) + +The related objects also get two methods, ``get_next_in_order()`` and +``get_previous_in_order()``, which can be used to access those objects in their +proper order. Assuming the ``Answer`` objects are ordered by ``id``:: + + >>> answer = Answer.objects.get(id=2) + >>> answer.get_next_in_order() + <Answer: 3> + >>> answer.get_previous_in_order() + <Answer: 1> + ``ordering`` ------------ |
