Zilong Li
Zilong Li

Reputation: 958

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

Upvotes: 3

Views: 590

Answers (1)

Zilong Li
Zilong Li

Reputation: 958

According to Taggit documentation:

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

Upvotes: 1

Related Questions