is_staff 字段未显示在 Django 管理中
is_staff field is not showing in Django admin
is_staff 被定义为布尔字段,但其复选框在管理页面中不可见。但是is_admin是可见的,可以改变。
我无法使用 views.py
更改该字段
class Users(AbstractBaseUser, PermissionsMixin):
objects = UserManager()
mobile_no = models.IntegerField(_('MobNumber'), null=True, blank=True,unique=True)
email = models.EmailField(_('Email'), max_length=75, null=False, blank=False)
first_name = models.CharField(_('FirstName'), max_length=50, null=True, blank=True)
last_name = models.CharField(_('LastName'), max_length=70, null=True, blank=True)
role = models.CharField(_('Role'), max_length=70, null=True, blank=True)
location = models.CharField(_('Location'), max_length=70, null=True, blank=True)
date_time = models.DateTimeField(_('DateTime'), auto_now=True, null=True, blank=True)
activated = models.BooleanField(_('Activated'), default=False)
is_admin = models.BooleanField(_('is_admin'), default=False)
is_staff = models.BooleanField(_('is_staff'), default=False)
def __unicode__(self):
return str(self.mobile_no)
def __str__(self):
return str(self.mobile_no)
def get_full_name(self):
return self.first_name + " " + self.last_name
class Meta:
ordering = ['-id']
@property
def is_staff(self):
return self.is_admin
def has_perm(self, perm, obj=None):
return self.is_admin
def has_module_perms(self, app_label):
return self.is_admin
USERNAME_FIELD = 'mobile_no'
REQUIRED_FIELDS = ['role']
您可以通过导入和继承来编辑 admin.py 中的用户管理员。这是一个例子:
# admin.py
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
class UserAdmin(BaseUserAdmin):
model = Users
list_display = ('mobile_no', 'email', 'first_name', 'last_name', 'role', 'location')
fieldsets = (
(('Personal info'), {'fields': ('first_name', 'last_name',)}),
(('Permissions'), {'fields': ('activated', 'is_staff', 'is_superuser', 'groups')}),
(('Important dates'), {'fields': ('date_time', 'last_login')}),
)
class Meta:
model = User
admin.site.register(User, UserAdmin)
is_staff 被定义为布尔字段,但其复选框在管理页面中不可见。但是is_admin是可见的,可以改变。
我无法使用 views.py
更改该字段class Users(AbstractBaseUser, PermissionsMixin):
objects = UserManager()
mobile_no = models.IntegerField(_('MobNumber'), null=True, blank=True,unique=True)
email = models.EmailField(_('Email'), max_length=75, null=False, blank=False)
first_name = models.CharField(_('FirstName'), max_length=50, null=True, blank=True)
last_name = models.CharField(_('LastName'), max_length=70, null=True, blank=True)
role = models.CharField(_('Role'), max_length=70, null=True, blank=True)
location = models.CharField(_('Location'), max_length=70, null=True, blank=True)
date_time = models.DateTimeField(_('DateTime'), auto_now=True, null=True, blank=True)
activated = models.BooleanField(_('Activated'), default=False)
is_admin = models.BooleanField(_('is_admin'), default=False)
is_staff = models.BooleanField(_('is_staff'), default=False)
def __unicode__(self):
return str(self.mobile_no)
def __str__(self):
return str(self.mobile_no)
def get_full_name(self):
return self.first_name + " " + self.last_name
class Meta:
ordering = ['-id']
@property
def is_staff(self):
return self.is_admin
def has_perm(self, perm, obj=None):
return self.is_admin
def has_module_perms(self, app_label):
return self.is_admin
USERNAME_FIELD = 'mobile_no'
REQUIRED_FIELDS = ['role']
您可以通过导入和继承来编辑 admin.py 中的用户管理员。这是一个例子:
# admin.py
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
class UserAdmin(BaseUserAdmin):
model = Users
list_display = ('mobile_no', 'email', 'first_name', 'last_name', 'role', 'location')
fieldsets = (
(('Personal info'), {'fields': ('first_name', 'last_name',)}),
(('Permissions'), {'fields': ('activated', 'is_staff', 'is_superuser', 'groups')}),
(('Important dates'), {'fields': ('date_time', 'last_login')}),
)
class Meta:
model = User
admin.site.register(User, UserAdmin)