Skip to content

Get tags applied to a device via nbshell #16360

Answered by candlerb
Mailstorm-ctrl asked this question in Q&A
Discussion options

You must be logged in to vote

AKA: if tag not in parent.tags: fail

It would have been helpful if you had shown the actual python code you tried, and the actual response.

tags is not a list or queryset, it's a database manager object. tags.all() will give you a queryset, which you can convert into a list if you want or construct an in query. Note that the tags themselves are are objects.

>>> i = IPAddress.objects.get(address="10.12.0.1/24")
>>> i.tags
<taggit.managers._TaggableManager object at 0x7bfdaf4e4cb0>
>>> i.tags.all()
<RestrictedQuerySet [<Tag: gateway>]>
>>> list(i.tags.all())
[<Tag: gateway>]
>>> Tag.objects.get(name="gateway") in i.tags.all()
True

If you are looking for a specific tag then there is a sim…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@candlerb
Comment options

@Mailstorm-ctrl
Comment options

Answer selected by Mailstorm-ctrl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants