Ticket #1354: django.order_with_respect_to.patch
File django.order_with_respect_to.patch, 2.1 KB (added by , 19 years ago) |
---|
-
django/db/models/base.py
125 178 if opts.order_with_respect_to: 126 179 cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True) 127 180 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)) 128 183 129 184 # Give the class a docstring -- its definition. 130 185 if cls.__doc__ is None: … … 278 333 cachename = "__%s_order_cache" % is_next 279 334 if not hasattr(self, cachename): 280 335 op = is_next and '>' or '<' 281 order_field = self. order_with_respect_to336 order_field = self._meta.order_with_respect_to 282 337 obj = self._default_manager.get_object(order_by=('_order',), 283 338 where=['%s %s (SELECT %s FROM %s WHERE %s=%%s)' % \ 284 339 (backend.quote_name('_order'), op, backend.quote_name('_order'), … … 394 449 cursor = connection.cursor() 395 450 # Example: "SELECT id FROM poll_choices WHERE poll_id = %s ORDER BY _order" 396 451 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), 400 455 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) 402 457 cursor.execute(sql, [rel_val]) 403 458 return [r[0] for r in cursor.fetchall()]