On Feb 8, 2010, at 7:56 AM, eaman wrote:

I'm up to code those two methods...
If some one is interested in this thread I managed to code
these two methods: get_next | get_prev
in order to get a previous or next item in a set right from my model:
- http://dpaste.com/155961/

Now that you've got a date attribute, why not use that for next and previous?

If you don't want to do that, you still might consider returning a real object instance, and then giving the model a get_absolute_url() method and calling that in the template. That will save you hardcoding the links in the template.

But if it's just an id you want, the following might be more efficient:

def get_next(self):
all_ids = Foto.objects.filter(galleria = self.galleria, id__gt=self.id).values_list("id",flat=True).order_by("id")
    try:
        return min(all_ids)
    except ValueError:
        return None

Then reverse that (id__lt=self.id and use the max python function) for get_prev()

Hope that's helpful,
Eric


- Is there a better way to get the highest  'previous' item then
using
   aggregate(Max('id'))    ?

- I guess the if /else conditional loop that should check the
existence of the prev | next item is suboptimal...

/eaman

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


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

Reply via email to