B
B
Boldy2014-11-19 00:25:07
Django
Boldy, 2014-11-19 00:25:07

How to use methods in templates in django?

There is a model with a method that returns a queryset with one argument. How can I use this method in a template?

def get_relative_children(self, level):
        result = self.get_descendants().filter(level=self.get_level() + level)=

Wanted to do this:
{% for child in get_relative_children(1) %}
<p> {{ child.id }} </p>
{% endfor %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey K, 2014-11-19
@Boldy

No way, methods are called without parameters https://docs.djangoproject.com/en/1.7/topics/templ...
Solution: write a template filter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question