My models.py
class X(models.Model):
...
tags = TaggableManager()
How to add tags to an object. If I do:
x = X.objects.get(pk = 123)
x.tags.add( "sample_tag" )
It adds the tag twice, if the tag with same name (i.e "sample_tag" in the above in the case) has been previously created. Now when I retrieve tags :
>>> x.tags.all()
>>> [<Tag: sampletag>, <Tag: Sample_tag>]
How to do solve this problem. I want to add a new tag only if its not created before, and if created just refer the new object to that tag?
django-taggit does exactly what you want, but in your case
sampletag
!=Sample_tag
, so anotherTag
instance is created.