简体   繁体   中英

django-taggit: how to programmatically create tags?

For example:

tags_input = "hello, foo, bar, ok"
tagset = tag_parser(tags_input) # {'bar', 'foo', 'hello', 'ok'}

obj = Post(title=title, tags=tagset)
obj.save()

The above snippet doesn't seem to work. How can I create tags programmatically? eg in views

According to Taggit documentation:

apple = Food.objects.create(name="apple")
apple.tags.add("red", "green", "delicious")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM