Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1857 -- Fixed get_previous_by_FIELD and get_next_by_FIELD to work

properly with keyword arguments. Patch from tom@jerakeen.org.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3157 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a8a133cc6cf4c3a5a2deb9d8989ba09b09ace736 1 parent ed6d728
Malcolm Tredinnick authored June 20, 2006
4  django/db/models/base.py
@@ -271,13 +271,13 @@ def _get_FIELD_display(self, field):
271 271
         value = getattr(self, field.attname)
272 272
         return dict(field.choices).get(value, value)
273 273
 
274  
-    def _get_next_or_previous_by_FIELD(self, field, is_next):
  274
+    def _get_next_or_previous_by_FIELD(self, field, is_next, **kwargs):
275 275
         op = is_next and '>' or '<'
276 276
         where = '(%s %s %%s OR (%s = %%s AND %s.%s %s %%s))' % \
277 277
             (backend.quote_name(field.column), op, backend.quote_name(field.column),
278 278
             backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column), op)
279 279
         param = str(getattr(self, field.attname))
280  
-        q = self.__class__._default_manager.order_by((not is_next and '-' or '') + field.name, (not is_next and '-' or '') + self._meta.pk.name)
  280
+        q = self.__class__._default_manager.filter(**kwargs).order_by((not is_next and '-' or '') + field.name, (not is_next and '-' or '') + self._meta.pk.name)
281 281
         q._where.append(where)
282 282
         q._params.extend([param, param, getattr(self, self._meta.pk.attname)])
283 283
         try:
2  tests/modeltests/lookup/models.py
@@ -128,6 +128,8 @@ def __str__(self):
128 128
 <Article: Article 2>
129 129
 >>> a2.get_next_by_pub_date()
130 130
 <Article: Article 3>
  131
+>>> a2.get_next_by_pub_date( headline__endswith = '6' )
  132
+<Article: Article 6>
131 133
 >>> a3.get_next_by_pub_date()
132 134
 <Article: Article 7>
133 135
 >>> a4.get_next_by_pub_date()

0 notes on commit a8a133c

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