我已經定製了用戶模型,這是模型:AttributeError的:「帳戶」對象有沒有屬性「is_staff」
from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import BaseUserManager
class AccountManager(BaseUserManager):
def create_user(self, username=None, password=None, **kwargs):
account = self.model(username=username)
account.set_password(password)
account.is_stuff = False
account.save()
return account
def create_superuser(self, username, password, **kwargs):
account = self.create_user(username, password, **kwargs)
account.is_admin = True
account.is_staff = True
account.save()
return account
class Account(AbstractBaseUser):
username = models.CharField(max_length=40, unique=True)
is_admin = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
initialized = models.BooleanField(default=False)
USERNAME_FIELD = 'username'
objects = AccountManager()
然後當我試圖把它拋出AttributeError: 'Account' object has no attribute 'is_staff'
所有用戶的列表。
class GetUserList(ListAPIView):
permission_classes = (permissions.IsAdminUser,)
queryset = Account.objects.all()
serializer_class = AccountSerializer
你還沒有在你的模型上罰款一個'is_staff'字段。你打算? –