在模型中使用admin-user

时间:2015-12-01 20:39:04

标签: python django

我刚刚开始摆弄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'对象没有属性'用户'

1 个答案:

答案 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