views:

43

answers:

2

I have in my Django controller a function that is called as follows:

trip.driverTrip.filter(status='pending')

What it will be the equivalent of calling this in a template. If I just want to call the filter function, the following will suffice:

{{trip.driverTrip.filter}}

But is there a way to pass it arguments ?

A: 

http://stackoverflow.com/questions/1333189/django-template-system-calling-a-function-inside-a-model/1333277#1333277 explains, you can't do it directly, but it that site also suggests a workaround.

Mike Morearty
+1  A: 

There are no controllers in Django ... Do you mean a view ;) ?

The equivalent in a template would be :

{{ trip.driverTrip|filter:"pending" }}

However, for this to work, your function filter has to be registered as a template filter, and 'loaded' in your template. You cannot just call any function (or method) like this. Plus, if you do this, assuming that the preceding conditions are fulfilled it means that you pass trip.driverTrip as the first argument to filter, and "pending" is an additional argument.

Does this answer your question ?

sebpiq
Yes, view, sorry, and yes, it does answer my question perfectly :). Thank you!
Nicolae Surdu