0

How to change the template tag based on another template tag.

task_count = {1 :3, 2: 0, 3: 1} --- i manually created

task_type = {1:rebuild,2:upgrade,3:provisioning} ---- this from table

I want to get the task count for ex: if the task id 1 then "Rebuild:3".

I tried the below code it's not working

{% for task in TaskTypeTag %}
{{task_count.{{task.id}}}}
Mohamed Naveen
  • 131
  • 1
  • 4
  • 8

1 Answers1

0

You have to create a custom filter.

@register.filter(name='cut')
def get_count(value, arg):
    task_count = {1 :3, 2: 0, 3: 1}
    return "{}:{}".format(value, task_count[arg])

Then you will be able to use it in your template.

{% for task in TaskTypeTag %}
    {{task.name|get_count:task.id}}

For more information, click here.

Davit Tovmasyan
  • 3,238
  • 2
  • 20
  • 36