On Feb 8, 3:38 am, Eric Abrahamsen <gir...@gmail.com> wrote:
[CUT]
> Now that you've got a date attribute, why not use that for next and  
> previous?
1. Date based next and prev go throught the whole photo set,
but I prefer next and prev to provide only items inside a gallery.
But I guess that's just me unable to pass an extra parameter
to the generic view.

2. I'm learning: I wanted to test an other way to get this navigation
links,
coding some custom methods.

> If you don't want to do that, you still might consider returning a  
> real object instance,
Yes this should be better, it could be more userfull if I had to
generate a PDF or some other kind of output.

> 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.
- http://docs.djangoproject.com/en/dev/ref/models/instances/#get-absolute-url
Thanks for the advice: this will make deployment and refactoring
easier.

>
> 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
Oh yes thanks a lot, code examples are really useful to  me as I'm not
yet very familiar with of all this 'snaky' dotted object syntax /
traversing;
I'll get into the django shell and play a bit with this.

Thanks for all this suggestions.

-- 
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