我刚刚开始摆弄Django,现在我尝试使用模型中管理页面中可用的用户。
这是我的模特:
class Game(models.Model):
started_at = models.DateTimeField()
class Player(models.Model):
game = models.ForeignKey(Game)
user = models.ForeignKey(models.User)
但这不起作用:python manage.py makemigrations
返回:
AttributeError:' module'对象没有属性'用户'
答案 0 :(得分:3)
默认User
模型可从django.contrib.auth.models
获得:
from django.contrib.auth.models import User
from django.db import models
class Game(models.Model):
started_at = models.DateTimeField()
class Player(models.Model):
game = models.ForeignKey(Game)
user = models.ForeignKey(User) # models.User doesn't exist