From 4c7508cd6b291a9bd4aeb677485d483384329b04 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 17 Jun 2021 23:11:31 +0200 Subject: [PATCH] tag to call a method with (multiple)args --- InvenTree/part/templatetags/inventree_extras.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index 0cfbe789c4..90e91e167f 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -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 """