Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 22fc30be5a54d1027956a9ae668eb24d401483bc 1 parent 4a1fd44
Simon Meers authored December 06, 2010

Showing 1 changed file with 26 additions and 0 deletions. Show diff stats Hide diff stats

  1. 26  docs/ref/models/options.txt
26  docs/ref/models/options.txt
@@ -143,6 +143,32 @@ do this::
143 143
         class Meta:
144 144
             order_with_respect_to = 'question'
145 145
 
  146
+When ``order_with_respect_to`` is set, two additional methods are provided to
  147
+retrieve and to set the order of the related objects: ``get_RELATED_order()``
  148
+and ``set_RELATED_order()``, where ``RELATED`` is the lowercased model name. For
  149
+example, assuming that a ``Question`` object has multiple related ``Answer``
  150
+objects, the list returned contains the primary keys of the related ``Answer``
  151
+objects::
  152
+
  153
+    >>> question = Question.objects.get(id=1)
  154
+    >>> question.get_answer_order()
  155
+    [1, 2, 3]
  156
+
  157
+The order of a ``Question`` object's related ``Answer`` objects can be set by
  158
+passing in a list of ``Answer`` primary keys::
  159
+
  160
+    >>> question.set_answer_order([3, 1, 2])
  161
+
  162
+The related objects also get two methods, ``get_next_in_order()`` and
  163
+``get_previous_in_order()``, which can be used to access those objects in their
  164
+proper order. Assuming the ``Answer`` objects are ordered by ``id``::
  165
+
  166
+    >>> answer = Answer.objects.get(id=2)
  167
+    >>> answer.get_next_in_order()
  168
+    <Answer: 3>
  169
+    >>> answer.get_previous_in_order()
  170
+    <Answer: 1>
  171
+
146 172
 ``ordering``
147 173
 ------------
148 174
 

0 notes on commit 22fc30b

Please sign in to comment.
Something went wrong with that request. Please try again.