Ticket #1857: get_next_previous.diff
File get_next_previous.diff, 1.6 KB (added by , 19 years ago) |
---|
-
django/db/models/base.py
258 258 value = getattr(self, field.attname) 259 259 return dict(field.choices).get(value, value) 260 260 261 def _get_next_or_previous_by_FIELD(self, field, is_next ):261 def _get_next_or_previous_by_FIELD(self, field, is_next, **kwargs): 262 262 op = is_next and '>' or '<' 263 263 where = '(%s %s %%s OR (%s = %%s AND %s.%s %s %%s))' % \ 264 264 (backend.quote_name(field.column), op, backend.quote_name(field.column), 265 265 backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column), op) 266 266 param = str(getattr(self, field.attname)) 267 q = self.__class__._default_manager. order_by((not is_next and '-' or '') + field.name, (not is_next and '-' or '') + self._meta.pk.name)267 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) 268 268 q._where.append(where) 269 269 q._params.extend([param, param, getattr(self, self._meta.pk.attname)]) 270 270 try: -
tests/modeltests/lookup/models.py
128 128 Article 2 129 129 >>> a2.get_next_by_pub_date() 130 130 Article 3 131 >>> a2.get_next_by_pub_date( headline__endswith = '6' ) 132 Article 6 131 133 >>> a3.get_next_by_pub_date() 132 134 Article 7 133 135 >>> a4.get_next_by_pub_date()