0

I have a problem when I try to import my model "Book" and my model "Comment" from different apps.

My Settings.py

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

books/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)

and my comments/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)

I was trying so mamy things but nothing works :(

The error is:

  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
Taku
  • 31,927
  • 11
  • 74
  • 85
Miguel Toledano
  • 387
  • 5
  • 19

0 Answers0