Django 1.11:无法导入名称Book

时间:2017-04-16 21:33:21

标签: python django

当我尝试从不同的应用导入我的模型“Book”和我的模型“Comment”时,我遇到了问题。

我的设置.py

INSTALLED_APPS = [
    ...
    'books',
    'comments',
    ...
]

书籍/ models.py

from comments.models import Comment

class Book(models.Model):
  owner = models.ForeignKey(User, on_delete=models.CASCADE)
  title = models.CharField(max_length=200)
  slug = models.SlugField(unique=True)
  autor = models.CharField(max_length=200)
  description = models.TextField()
  likes = models.PositiveIntegerField(default=0)
  created_date = models.DateTimeField(default=timezone.now)
  published_date = models.DateTimeField(blank=True, null=True)
  files = models.FileField(upload_to=upload_location, validators=[validate_file_extension])
  book_type = models.CharField(max_length=100, choices=Book_Type_Choices)
  tags = TaggableManager()
  comment = models.ForeignKey(Comment)

和我的评论/ models.py

from books.models import Book

class Comment(models.Model):
  book = models.ForeignKey(Book, related_name='cooments')
  user = models.ForeignKey(User, unique=False)
  text = models.CharField(max_length=250)
  created_date = models.DateTimeField(default=timezone.now)
  approved_comment = models.BooleanField(default=False)

我尝试了很多可爱的东西,但没有任何作用:(

错误是:

  File "C:\Users\a_niu\Desktop\Proyectos\Django\tt\Tescha-books\books\models.py", line 12, in <module>
from comments.models import Comment
  File "C:\Users\a_niu\Desktop\Proyectos\Django\tt\Tescha-books\comments\models.py", line 5, in <module>
from books.models import Book
 ImportError: cannot import name Book

0 个答案:

没有答案