[Answered ]-I am getting this error using django taggit "Can't call add with a non-instance manager"

2👍

You are trying to add tags to the Post manager.
You want to add tags to a Post instance.

You need a saved Post instance before you can add the tags

e.g.

post_instance = Post.objects.get_or_create(foo=bar)
tags = post_instance.tags.add("Musica", "video")

0👍

With the aide of @luke_aus answer I figured it out. this is just what my code looks like now for others who may want to see how to actually do it. It went from this.

    for entry in entries:
            post = Post()
            post.title = entry['text']
            title = post.title
            if not Post.objects.filter(title=title):
                post.title = entry['text']
                post.name = entry['name']
                post.url = entry['url']
                post.body = entry['comments']
                post.image_url = entry['src']
                post.video_path = entry['embed']
                post.author = entry['author']
                post.video = entry['video']
                post.status = 'draft'
                post.save()

to this

    for entry in entries:
            post = Post()
            post.title = entry['text']
            title = post.title
            if not Post.objects.filter(title=title):
                post.title = entry['text']
                post.name = entry['name']
                post.url = entry['url']
                post.body = entry['comments']
                post.image_url = entry['src']
                post.video_path = entry['embed']
                post.author = entry['author']
                post.video = entry['video']
                post.status = 'draft'
                post.save()

                saved_post = Post.objects.get(title=title)
                tags = saved_post.tags.add("Musica", "video")
                post.tags = tags
                post.save()

hope this helps someone

👤losee

Leave a comment