Ticket #8975: 8975.diff

File 8975.diff, 1.7 KB (added by dwillis, 5 years ago)
  • docs/ref/models/options.txt

    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:: 
    143143        class Meta:
    144144            order_with_respect_to = 'question'
    145145
     146When order_with_respect_to is set to a related object, it also provides two methods
     147to 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
     149that a ``Question`` object has multiple related ``Answer`` objects, the list returned
     150contains 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
     156The order of a ``Question`` object's related ``Answer`` objects can be set by passing in
     157a list of ``Answer`` object ids::
     158
     159    >>> question.set_answer_order([3, 1, 2])
     160
     161The related objects also get two methods, ``get_next_in_order()`` and ``get_previous_in_order()``,
     162which can be used to access those objects in their proper order. Assuming the ``Answer`` objects
     163are 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
    146171``ordering``
    147172------------
    148173
Back to Top