#5845: _get_next_or_previous_by_FIELD returns the same row in first row
------------------------------------+---------------------------------------
Reporter:  [EMAIL PROTECTED]  |       Owner:  nobody          
  Status:  new                      |   Component:  Database wrapper
 Version:  SVN                      |    Keywords:                  
   Stage:  Unreviewed               |   Has_patch:  0               
------------------------------------+---------------------------------------
 I'm using sqlite3

 when i use:

 {{{next = post.get_next_by_date_added()}}}

 if post is the first date:

 next becomes equale to post.

 otherwise this works fine...

 i didn't want to change the sql generated or something like that because
 i'm really new to the framework,
 so i decided to do little fixing before returning a value:

 {{{
     def _get_next_or_previous_by_FIELD(self, field, is_next, **kwargs):
         op = is_next and '>' or '<'
         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)
         param = str(getattr(self, field.attname))
         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)
         q._where.append(where)
         q._params.extend([param, param, getattr(self,
 self._meta.pk.attname)])
         try:
             i=0
             while q[i] == self:
                 i=i+1
             return q[i]
         except IndexError:
             raise self.DoesNotExist, "%s matching query does not exist." %
 self.__class__._meta.object_name
 }}}

 I changed

 {{{            return q[0]}}}

 into

 {{{
             i=0
             while q[i] == self:
                 i=i+1
             return q[i]
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/5845>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to