Question

I wanted to add a StackOverflow-style tag input to a blog model of mine. This is a model that has a lot of data already in it.

class BlogPost(models.Model):
    # my blog fields

try:
    tagging.register(BlogPost)
except tagging.AlreadyRegistered:
    pass

I thought that was all I needed so I went through my old database of blog posts (this is a newly ported blog) and copied the tags in. It worked and I could display tags and filter by tag.

However, I just wrote a new BlogPost and realise there's no tag field there.

Reading the documentation (coincidentally, dry enough to be used as an antiperspirant), I found the TagField. Thinking this would just be a manager-style layer over the existing tagging register, I added it. It complained about there not being a Tag column.

I'd rather not denormalise on tags just to satisfy create an interface for inputting them. Is there a TagManager class that I can just set on the model?

    tags = TagManager() # or somesuch
Was it helpful?

Solution

Did you try using TagField() in the model instead of registering the model?

from tagging.fields import TagField

class BlogPost(models.Model):
    # ...
    tags = TagField()

OTHER TIPS

Like istruble said (sorry I can't comment above): Did you try using TagField() in the model instead of registering the model?

from tagging.fields import TagField

class BlogPost(models.Model):
    # ...
    tags = TagField()

But after that, you have to change your database table. I would recommend to make a backup of your database. Then run manage.py reset APPNAME check out how the table has changed. Restore the backup and try to alter the table, so that it looks like the new one. In this way you wont lose your data ;)

And remember, syncdb will not work since the table exist allready.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top