On 3/11/06, Glenn Tenney <[EMAIL PROTECTED]> wrote: > > In my templates, I'd like to be able to (for example): > Given an "object_list" of rateable things, I'd like to > then get the "Rating" valules for the current user. > I'm trying to figure out a good way to do this. > > I don't see any way in a template to pass an argument > to a method. i.e. I can do
> Is there a better way? What am I missing????? One of the design goals of the Django templates is to force the separation of view logic from the template. To this end, there are deliberately very few mechanisms for computation or method calls in Django templates. If you feel a need to make a method call with arguments, this suggests that there is some form of logic operation that should be merged into the view, rather than the template itself. The Django way would be to evaluate the method in the view, and pass the result to the template as part of the context. In your case, build up a dict: ratings = dict(zip(object_list, [obj.rating(who__id=user) for obj in object_list])) and pass that map, plus the object_list and user as part of the context object to the template. Then, in the template, you can iterate over the object_list or the dictionary; dictionary lookup is supported in templates; {% ratings.obj %} will expand as ratings[obj] Why do it this way? Well, if you every decide to change how ratings are found, you don't have to change the template - you just have to change the mechanism by which ratings are determined in the view. Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---