tag to call a method with (multiple)args

This commit is contained in:
Matthias 2021-06-17 23:11:31 +02:00
parent 58b6bbb236
commit 4c7508cd6b

View File

@ -219,6 +219,18 @@ def keyvalue(dict, key):
return dict[key]
@register.simple_tag()
def call_method(obj, method_name, *args):
"""
enables calling model methods / functions from templates with arguments
usage:
{% call_method model_object 'fnc_name' argument1 %}
"""
method = getattr(obj, method_name)
return method(*args)
@register.simple_tag()
def authorized_owners(group):
""" Return authorized owners """