I have defined a dictionary of lookup arguments in my manages so I can
reuse them everywhere I want the same behavior...

On Jun 10, 3:12 am, Jonathan Stockdill
<[EMAIL PROTECTED]> wrote:
> I found myself in a similar position and used the following:
>      def get_next_pub(self):
>        return self.get_next_by_pub_date(pub_date__lt=datetime.now
> (),is_draft=False)
>      def get_previous_pub(self):
>        return self.get_previous_by_pub_date(pub_date__lt=datetime.now
> (),is_draft=False)
>
> but already have these filters in a Manager and was wondering, is
> there a way to specify the methods to use a different manager than
> the default?
>
> Thank you,
>
> --jon
>
> On May 8, 2007, at 8:51 PM, Malcolm Tredinnick wrote:
>
>
>
> > On Mon, 2007-05-07 at 22:32 +0000, roderikk 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?
>
> > I wouldn't override this function. Just write your own function with
> > whatever name you like that does the work you want. The
> > get_next_by_FOO() auto-functions are useful in the case of a
> > particular
> > ordered type of field. If they don't do what you want, just write
> > another method that does the "right thing". The name is not important,
> > but I would avoid overriding and automatically created function so
> > that
> > you don't have to always think about whether the automatically created
> > thing is being called or your version (it's harder to debug).
>
> >> 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.
>
> > Would also work.
>
> >> 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 %}
>
> > You can't do complex processing like this in templates. It's a sign
> > that
> > you should be making things easier for yourself back in the view or in
> > the model, as in one of your previous suggestions.
>
> > Regards,
> > Malcolm


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

Reply via email to