From cf276407ea0f3960f3d265691c14f64c9700101b Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 30 Jan 2006 04:05:53 +0000 Subject: [PATCH] magic-removal: Fixed _get_next_or_previous_by_FIELD() to use new-style lookup git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2175 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/base.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/django/db/models/base.py b/django/db/models/base.py index 79bd58acf1..b7f7e08315 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -267,14 +267,14 @@ class Model(object): def _get_next_or_previous_by_FIELD(self, field, is_next, **kwargs): op = is_next and '>' or '<' - kwargs.setdefault('where', []).append('(%s %s %%s OR (%s = %%s AND %s.%s %s %%s))' % \ + where = '(%s %s %%s OR (%s = %%s AND %s.%s %s %%s))' % \ (backend.quote_name(field.column), op, backend.quote_name(field.column), - backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column), op)) + backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column), op) param = str(getattr(self, field.attname)) - kwargs.setdefault('params', []).extend([param, param, getattr(self, self._meta.pk.attname)]) - kwargs['order_by'] = [(not is_next and '-' or '') + field.name, (not is_next and '-' or '') + self._meta.pk.name] - kwargs['limit'] = 1 - return self.__class__._default_manager.get(**kwargs) + q = self.__class__._default_manager + q = q.order_by((not is_next and '-' or '') + field.name, (not is_next and '-' or '') + self._meta.pk.name) + q = q.extra(where=where, params=[param, param, getattr(self, self._meta.pk.attname)]) + return q[0] def _get_next_or_previous_in_order(self, is_next): cachename = "__%s_order_cache" % is_next