我具有以下目录结构:
.
├── LMS
│ ├── __init__.py
│ ├── __pycache__
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── VENV
│ ├── bin
│ ├── include
│ ├── lib
│ └── pyvenv.cfg
├── assets
│ ├── css
│ ├── images
│ └── js
├── courses
│ ├── __init__.py
│ ├── __pycache__
│ ├── admin.py
│ ├── apps.py
│ ├── fields.py
│ ├── fixtures
│ ├── forms.py
│ ├── migrations
│ ├── models.py
│ ├── templates
│ ├── templatetags
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── db.sqlite3
├── manage.py
├── media
│ ├── course_images
│ ├── files
│ └── images
├── templates
│ └── base.html
└── users
├── __init__.py
├── __pycache__
├── admin.py
├── apps.py
├── forms.py
├── migrations
├── models.py
├── templates
├── tests.py
├── urls.py
└── views.py
现在我正尝试通过以下方式将courses.models.Course
导入users.models
:
from courses.models import Course
更新:这是
courses.models
class Subject(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField(max_length=200, unique=True)
class Meta:
ordering = ('title',)
def __str__(self):
return self.title
class Course(models.Model):
owner = models.ForeignKey(Account,
related_name='courses_created',
on_delete=models.PROTECT)
subject = models.ForeignKey(Subject,
related_name='courses',
on_delete=models.PROTECT)
title = models.CharField(max_length=200)
slug = models.SlugField(max_length=200, unique=True)
overview = models.TextField()
created = models.DateTimeField(auto_now_add=True)
course_img = models.ImageField(upload_to='course_images/')
class Meta:
ordering = ('-created',)
def __str__(self):
return self.title
但给出了以下错误:
from courses.models import Course
ImportError: cannot import name 'Course' from 'courses.models'
(/Users/abdul/PycharmProjects/LMS/courses/models.py)