Ticket #1857: get_next_previous.diff

File get_next_previous.diff, 1.6 KB (added by tom@…, 18 years ago)
  • django/db/models/base.py

     
    258258        value = getattr(self, field.attname)
    259259        return dict(field.choices).get(value, value)
    260260
    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):
    262262        op = is_next and '>' or '<'
    263263        where = '(%s %s %%s OR (%s = %%s AND %s.%s %s %%s))' % \
    264264            (backend.quote_name(field.column), op, backend.quote_name(field.column),
    265265            backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column), op)
    266266        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)
    268268        q._where.append(where)
    269269        q._params.extend([param, param, getattr(self, self._meta.pk.attname)])
    270270        try:
  • tests/modeltests/lookup/models.py

     
    128128Article 2
    129129>>> a2.get_next_by_pub_date()
    130130Article 3
     131>>> a2.get_next_by_pub_date( headline__endswith = '6' )
     132Article 6
    131133>>> a3.get_next_by_pub_date()
    132134Article 7
    133135>>> a4.get_next_by_pub_date()
Back to Top