Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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? e.g. in views

like image 649
Zilong Li Avatar asked Apr 02 '26 22:04

Zilong Li


1 Answers

According to Taggit documentation:

apple = Food.objects.create(name="apple")
apple.tags.add("red", "green", "delicious")
like image 191
Zilong Li Avatar answered Apr 04 '26 10:04

Zilong Li