Reputation: 1
Im currently learning django with the book "Django 2" by Antonio Melé. I got an error when I import "from taggit.managers import TaggableManager". I already install django-taggit and django-extensions. I also already added 'taggit' to INSTALLED_APPS. Here is my settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog.apps.BlogConfig',
'taggit'
]
My models.py (There are more classes but I put the one that im working on):
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse
from taggit.managers import TaggableManager
class Post (models.Model):
STATUS_CHOICES = (
('draft', 'Draft'),
('published', 'Published'),
)
title = models.CharField(max_length=150)
slug = models.SlugField(max_length=250, unique_for_date='publish')
author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='blog_posts')
body = models.TextField()
publish = models.DateTimeField(default=timezone.now)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='published')
class Meta:
ordering = ('-publish',)
def __str__(self):
return self.title
objects = models.Manager()
published = PublishedManager()
def get_absolute_url(self):
return reverse('blog:post_detail', args=[self.publish.year, self.publish.month, self.publish.day, self.slug])
tags = TaggableManager()
Image of the error, just in case
I ran python manage.py shell and after the following:
from blog.models import Post
post = Post.objects.get(id=1)
post.tag.add('post1', 'blogpost', 'tag1')
post.tags.all()
And the tags were added successfuly.
Upvotes: 0
Views: 601
Reputation: 1
I know it is 11 months, but I had the same problem and I know how to fix it. You need to add extra path for analysis in vscode settings. look at this image
Upvotes: 0
Reputation: 1
Restart your python server then run the initial migration
Upvotes: 0