Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return object tags as a list

Using django-tagging, for an object that has multiple tags assigned to it, how can I return a simple list of tag names?

object.tags() returns an object that is not easily translated to json, and TaggableManager is not iterable.

Any other ways?

like image 223
Goro Avatar asked Jan 17 '23 22:01

Goro


1 Answers

There is a undocumented function in TaggableManager called 'get_query_set', from which it is easy to get the list:

tagsList = []
for tag in foobar.tags.get_query_set():
  tagsList.append(tag.name)
like image 72
Goro Avatar answered Jan 22 '23 08:01

Goro