Ticket #1354: django.order_with_respect_to.patch

File django.order_with_respect_to.patch, 2.1 KB (added by andreas@…, 19 years ago)
  • django/db/models/base.py

     
    125178        if opts.order_with_respect_to:
    126179            cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True)
    127180            cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False)
     181            setattr(opts.order_with_respect_to.rel.to, 'get_%s_order' % cls.__name__.lower(), curry(method_get_order, cls))
     182            setattr(opts.order_with_respect_to.rel.to, 'set_%s_order' % cls.__name__.lower(), curry(method_set_order, cls))
    128183
    129184        # Give the class a docstring -- its definition.
    130185        if cls.__doc__ is None:
     
    278333        cachename = "__%s_order_cache" % is_next
    279334        if not hasattr(self, cachename):
    280335            op = is_next and '>' or '<'
    281             order_field = self.order_with_respect_to
     336            order_field = self._meta.order_with_respect_to
    282337            obj = self._default_manager.get_object(order_by=('_order',),
    283338                where=['%s %s (SELECT %s FROM %s WHERE %s=%%s)' % \
    284339                    (backend.quote_name('_order'), op, backend.quote_name('_order'),
     
    394449    cursor = connection.cursor()
    395450    # Example: "SELECT id FROM poll_choices WHERE poll_id = %s ORDER BY _order"
    396451    sql = "SELECT %s FROM %s WHERE %s = %%s ORDER BY %s" % \
    397         (backend.quote_name(ordered_obj.pk.column),
    398         backend.quote_name(ordered_obj.db_table),
    399         backend.quote_name(ordered_obj.order_with_respect_to.column),
     452        (backend.quote_name(ordered_obj._meta.pk.column),
     453        backend.quote_name(ordered_obj._meta.db_table),
     454        backend.quote_name(ordered_obj._meta.order_with_respect_to.column),
    400455        backend.quote_name('_order'))
    401     rel_val = getattr(self, ordered_obj.order_with_respect_to.rel.field_name)
     456    rel_val = getattr(self, ordered_obj._meta.order_with_respect_to.rel.field_name)
    402457    cursor.execute(sql, [rel_val])
    403458    return [r[0] for r in cursor.fetchall()]
Back to Top