I have a model that is using django-taggit. I want to perform a South data migration that adds tags to this model. However, the .tags manager is not available from within a South migration where you have to use the South orm[‘myapp.MyModel’] API instead of the normal Django orm.
Doing something like this will throw an exception because post.tags is None.
post = orm['blog.Post'].objects.latest()
post.tags.add('programming')
Is it possible to create and apply tags with taggit from within a South data migration? If so, how?
Yes, you can do this, but you need to use
Taggit‘s API directly (i.e. create theTagandTaggedItem), instead of using theaddmethod.First, you’ll need to start by freezing
taggitinto this migration:Then your forwards method might look something like this (assuming you have a list of tags you want to apply to all Post objects.