Skip to content

how to get tags in export template jinja2 #15074

Answered by candlerb
henal3112 asked this question in Q&A
Discussion options

You must be logged in to vote

IIRC, the tags attribute has a method names() to give just the tag names, i.e. {{ device.tags.names() }}. Or slugs() if you want the tag slugs instead of tag names.

The way to explore these things is with nbshell.

# /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py nbshell
...
>>> o = IPAddress.objects.get(id=302)
>>> o.tags
<taggit.managers._TaggableManager object at 0x7f3a44fdc160>
>>> o.tags.all()
<RestrictedQuerySet [<Tag: proxy>]>
>>> list(o.tags.all())
[<Tag: proxy>]
>>> o.tags.names()
<RestrictedQuerySet ['proxy']>
>>> list(o.tags.names())
['proxy']
>>> o.tags.slugs()
<RestrictedQuerySet ['proxy']>
>>> list(o.tags.slugs())
['proxy']

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by henal3112
Comment options

You must be logged in to vote
1 reply
@KGT1
Comment options

Comment options

You must be logged in to vote
1 reply
@candlerb
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants