Ayeemba
Ayeemba

Reputation: 47

Taggit - how to initialize tags on creation?

class Test(models.Model):
    tags = TaggableManager()

In terminal:

t = Test(tags=["test_tag"])
t.tags //prints ['test_tag']
t.save()

However, when I load the object again and print it.

tags=[]

For some reason, it does not save properly.

Upvotes: 0

Views: 44

Answers (1)

Thanasis Karabatsis
Thanasis Karabatsis

Reputation: 11

As mentioned in the following ticket as well:

According to Taggit documentation:

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

Upvotes: 1

Related Questions