Well, sorry to be replying to myself but I have tried to solve it in
the following way:
I implemented these functions/properties in the model:
def _get_next_item_ID(self):
photo_list = [x for x in self.gallery.photo_set.all()]
ind = photo_list.index(self)+1
return photo_list[ind].id
def _get_previous_item_ID(self):
photo_list = [x for x in self.gallery.photo_set.all()]
ind = photo_list.index(self)-1
return photo_list[ind].id
nextID = property(_get_next_item_ID)
previousID = property(_get_previous_item_ID)
And by using an adaptation of the retrieve_object tag in the template
utilities package I could call this in the template as such:
{% load generic_content %}
{% retrieve_object gallery.photo photo.previousID as previousPhoto %}
(Just a note: the photo.previousID is only actually resolved when you
use the function from django.template.resolve_variable)
I don't think this is the most elegant way... therefore I would really
appreciate comments!
Thank you,
Roderik
On May 8, 12:32 am, roderikk <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I have recently started with django and have been able to do good work
> with the excellent documentation. Thank you.
>
> However, now I am a little baffled. I have created a gallery app. The
> model exists of a Gallery and Photo which has a foreign key to the
> Gallery.
>
> Now if I want to use the function photo.get_next_by_date in a template
> and there is a photo in another gallery which has that next date it
> will return that photo instead of the next one in the gallery.
>
> In my view there are a number of things I could do but I would like to
> hear from you which is best...
>
> First of all, if possible can I overwrite the get_next_by_FOO()
> function so it checks that the gallery is the same, but how?
>
> Second, I could create a page function in my Photo model as such:
>
> def page(self):
> photo_list = [x for x in self.gallery.photo_set.all()]
> ind = photo_list.index(self)
> return ind + 1
>
> And create a new template tag 'get_next_by_page' which checks for the
> page/index.
>
> Finally, in the template, which is fed with and object_list, I could
> also try to go back in the for loop (again, don't know how) and just
> get the previous/next objects in the list like so:
>
> {% for photo in object_list %}
> {% if has_next %}
> {# nextPhoto is object_list[currentCounter + 1 ] ? #}
> {% endif %}
> {% endfor %}
>
> I hope someone can help me. Thanks in advance. Roderik
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---