Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

magic-removal: Fixed #1354 -- Fixed order_with_respect_to. Thanks, an…

…dreas@mindpicnic.com

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2672 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 551536a82c29cc9ce27335b1368e1418c4060dad 1 parent d6863be
Adrian Holovaty authored April 11, 2006

Showing 1 changed file with 7 additions and 5 deletions. Show diff stats Hide diff stats

  1. 12  django/db/models/base.py
12  django/db/models/base.py
@@ -129,6 +129,8 @@ def _prepare(cls):
129 129
         if opts.order_with_respect_to:
130 130
             cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True)
131 131
             cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False)
  132
+            setattr(opts.order_with_respect_to.rel.to, 'get_%s_order' % cls.__name__.lower(), curry(method_get_order, cls))
  133
+            setattr(opts.order_with_respect_to.rel.to, 'set_%s_order' % cls.__name__.lower(), curry(method_set_order, cls))
132 134
 
133 135
         # Give the class a docstring -- its definition.
134 136
         if cls.__doc__ is None:
@@ -269,7 +271,7 @@ def _get_next_or_previous_in_order(self, is_next):
269 271
         cachename = "__%s_order_cache" % is_next
270 272
         if not hasattr(self, cachename):
271 273
             op = is_next and '>' or '<'
272  
-            order_field = self.order_with_respect_to
  274
+            order_field = self._meta.order_with_respect_to
273 275
             where = ['%s %s (SELECT %s FROM %s WHERE %s=%%s)' % \
274 276
                 (backend.quote_name('_order'), op, backend.quote_name('_order'),
275 277
                 backend.quote_name(opts.db_table), backend.quote_name(opts.pk.column)),
@@ -384,11 +386,11 @@ def method_get_order(ordered_obj, self):
384 386
     cursor = connection.cursor()
385 387
     # Example: "SELECT id FROM poll_choices WHERE poll_id = %s ORDER BY _order"
386 388
     sql = "SELECT %s FROM %s WHERE %s = %%s ORDER BY %s" % \
387  
-        (backend.quote_name(ordered_obj.pk.column),
388  
-        backend.quote_name(ordered_obj.db_table),
389  
-        backend.quote_name(ordered_obj.order_with_respect_to.column),
  389
+        (backend.quote_name(ordered_obj._meta.pk.column),
  390
+        backend.quote_name(ordered_obj._meta.db_table),
  391
+        backend.quote_name(ordered_obj._meta.order_with_respect_to.column),
390 392
         backend.quote_name('_order'))
391  
-    rel_val = getattr(self, ordered_obj.order_with_respect_to.rel.field_name)
  393
+    rel_val = getattr(self, ordered_obj._meta.order_with_respect_to.rel.field_name)
392 394
     cursor.execute(sql, [rel_val])
393 395
     return [r[0] for r in cursor.fetchall()]
394 396
 

0 notes on commit 551536a

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