在模特中
from django.db import models
from django.conf import settings
class Post(ThreadedComment):
author = models.ForeignKey(settings.AUTH_USER_MODEL)
我试过
from django.db import models
from django.contrib.auth.models import User
class Post(ThreadedComment):
author = models.ForeignKey(User)
错误:尝试makemigrations时
C:\Users\Home\lib\reflect\project\post\models.py:44: RemovedInDjango19Warning: The utilities in django.db.models.loading are deprecated in favor of the new application loading syste
m.
from django.db.models.loading import get_model
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Home\lib\reflect\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line
utility.execute()
File "C:\Users\Home\lib\reflect\lib\site-packages\django\core\management\__init__.py", line 312, in execute
django.setup()
File "C:\Users\Home\lib\reflect\lib\site-packages\django\__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Home\lib\reflect\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\Users\Home\lib\reflect\lib\site-packages\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\Home\lib\reflect\project\post\models.py", line 62, in <module>
class Post(ThreadedComment):
File "C:\Users\Home\lib\reflect\project\post\models.py", line 65, in Post
author = models.ForeignKey(settings.AUTH_USER_MODEL)
AttributeError: 'module' object has no attribute 'ForeignKey'
参考:https://docs.djangoproject.com/en/1.8/ref/contrib/auth/#django.contrib.auth.models.User
编辑: 完成models.py文件:http://pastebin.com/tyf9XDE5