On 12/16/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Ideally, this should be a something which is fetched in the view so I
> can just do {{ next_object.get_absolute_url }} in the template (and
> obviously for previous too)

It feels like what you want is a custom manager function; you could
define a manager class for the model and leave the built-in methods
alone, then add a new method which does the query you want.

Something like this (rough first attempt) might work:

class GetNextManager(models.Manager):
    def get_next_by_id(self, obj):
        next_queryset = self.filter(id__gt=obj.id)
        if next_queryset.count() > 0:
            return next_queryset.order_by('id')[0]
        return None

This queries the number of objects with ids higher than the one you
pass in; if there are any, it queries for and returns the one with the
lowest id. Otherwise it returns None, which will let you do boolean
tests to see whether you got an object out of it.

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to