我是一个django初学者,我想在AbstractUser中添加一个booleanfield,但它没有在管理员中显示booleanfield。
models.py
class CustomUser(AbstractUser):
selected = models.BooleanField(default=False)
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['selected',]
def __str__(self):
return self.username
admin.py
class MyUserChangeForm(UserChangeForm):
class Meta(UserChangeForm.Meta):
model = CustomUser
class UserAdmin(BaseUserAdmin):
form = MyUserChangeForm
list_display = ('username', 'first_name', 'last_name', 'email', 'is_staff', 'selected')
admin.site.register(CustomUser, UserAdmin)
settings.py
AUTH_USER_MODEL = 'football_app.CustomUser'
答案 0 :(得分:1)
更改
class UserAdmin(BaseUserAdmin):
至class UserAdmin(CustomUser):
编辑:像这样更新您的课程
class UserAdmin(admin.ModelAdmin):
list_display = ('username', 'first_name', 'last_name', 'email', 'is_staff', 'selected')
class Meta:
model = CustomUser
答案 1 :(得分:0)
您需要先取消注册当前的用户管理员。
admin.site.unregister(User)
admin.site.register(CustomUser, UserAdmin)