From 0e1f710e4aca3d760090e9446d6b5c4e03d5b1ac Mon Sep 17 00:00:00 2001
From: Derek Willis <dwillis@gmail.com>
Date: Sat, 18 Sep 2010 12:18:04 -0400
Subject: [PATCH] added docs for order_with_respect_to
---
docs/ref/models/options.txt | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/docs/ref/models/options.txt b/docs/ref/models/options.txt
index 3dfcdff..5d850e8 100644
a
|
b
|
do this::
|
143 | 143 | class Meta: |
144 | 144 | order_with_respect_to = 'question' |
145 | 145 | |
| 146 | When order_with_respect_to is set to a related object, it also provides two methods |
| 147 | to retrieve and to set the order of the related objects: ``get_RELATED_order()`` and |
| 148 | ``set_RELATED_order()``, where RELATED is the lowercased model name. For example, assuming |
| 149 | that a ``Question`` object has multiple related ``Answer`` objects, the list returned |
| 150 | contains the ids of the related ``Answer`` objects.:: |
| 151 | |
| 152 | >>> question = Question.objects.get(id=1) |
| 153 | >>> question.get_answer_order() |
| 154 | [1, 2, 3] |
| 155 | |
| 156 | The order of a ``Question`` object's related ``Answer`` objects can be set by passing in |
| 157 | a list of ``Answer`` object ids:: |
| 158 | |
| 159 | >>> question.set_answer_order([3, 1, 2]) |
| 160 | |
| 161 | The related objects also get two methods, ``get_next_in_order()`` and ``get_previous_in_order()``, |
| 162 | which can be used to access those objects in their proper order. Assuming the ``Answer`` objects |
| 163 | are ordered by id:: |
| 164 | |
| 165 | >>> answer = Answer.objects.get(id=2) |
| 166 | >>> answer.get_next_in_order() |
| 167 | <Answer: 3> |
| 168 | >>> answer.get_previous_in_order() |
| 169 | <Answer: 1> |
| 170 | |
146 | 171 | ``ordering`` |
147 | 172 | ------------ |
148 | 173 | |