I am trying to export a list of devices with their tags (since the device listing doesn't show the tags)
The taggit
API includes a names() method. Here's the export template I'm trying to use:
{% for device in queryset %}
{{ device.name }},{{ device.site }},{{ device.device_role }},{{ device.status }},{{ device.tags.names }}
{% endfor %}
The results with Jinja2 query language aren't useful, since it doesn't invoke the method:
storage1,WRN,Server,1,<bound method _TaggableManager.names of <taggit.managers._TaggableManager object at 0x7f80882c1668>>
If I use the Django template language then the method is invoked, but the results are ugly:
storage1,WRN,Server,1,<QuerySet ['4.1U', 'move1']>
(there the tags should be "4.1U" and "move1")
I tried adding 'join'
{% for device in queryset %}
{{ device.name }},{{ device.site }},{{ device.device_role }},{{ device.status }},{{ device.tags.names | join: ";" }}
{% endfor %}
This gives an error saying that join requires 2 arguments, only 1 given.
I finally ended up with this:
{% for device in queryset %}
{{ device.name }},{{ device.site }},{{ device.device_role }},{{ device.status }},{% for tag in device.tags.names %}{{tag}}{% if not forloop.last %};{% endif %}{%endfor %}{% endfor %}
It works, but is there a better way?