Example:
{{ model.function() }}
Thanks
Kai
It is possible to call methods which take no arguments, by doing
{{ model.method }}
Note that this has 'method', not 'method()' -- parentheses are not
used, and it is not possible to pass arguments to the method. This is
done because the template language is not meant to be a full
programming language; if you need to call something with arguments,
you will need to do it in your view and pass the result data to the
template, or write a custom template tag which returns the data you
want.
--
"May the forces of evil become confused on the way to your house."
-- George Carlin
On 12/2/06, James Bennett <ubern...@gmail.com> wrote:
> Note that this has 'method', not 'method()' -- parentheses are not
> used, and it is not possible to pass arguments to the method. This is
> done because the template language is not meant to be a full
> programming language; if you need to call something with arguments,
> you will need to do it in your view and pass the result data to the
> template, or write a custom template tag which returns the data you
> want.
Okay, thank you James. :)
Kai
Template:
<td>{{ movie.genres_title_list }}</td>
models.py:
def genres_title_list(self, separator=', '):
return separator.join([x.title for x in self.genres])
Prints nothing... idea anyone?
Kai
Which class is that in? Movie?
Are you sure that the movie you're using has genre, i.e., have you tried
it in the shell?
Todd
If I reconstruct the case correctly and `genres` is a relation to child
objects with ForeignKey to a Movie then `self.genres` by default should
look like `self.genre_set.all()`. Otherwise it will raise an exception
(because there is no `self.genres`) and the template system won't show
anything there.
On 12/3/06, Ivan Sagalaev <Man...@softwaremaniacs.org> wrote:
> Kai Kuehne wrote:
> [model.py]
>
> If I reconstruct the case correctly and `genres` is a relation to child
> objects with ForeignKey to a Movie then `self.genres` by default should
> look like `self.genre_set.all()`. Otherwise it will raise an exception
> (because there is no `self.genres`) and the template system won't show
> anything there.
No no, this is ok. I have tested it in the shell.
Greetings
Kai