所以我有一个继承自AbstractBaseUser的用户模型
from django.db import models
from django.core.exceptions import ValidationError
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
from User.userManager import CustUserManager
class User(AbstractBaseUser,PermissionsMixin):
fname = models.CharField(max_length=20, blank = False)
lname = models.CharField(max_length=20, blank = False)
email = models.EmailField(max_length=50, db_index = True, blank = False,primary_key=True)
course_id = models.CharField(max_length=20, default='DEFAULT VALUE')
USERNAME_FIELD = 'email'
objects = CustUserManager()
#Attributes for admin
is_admin = models.BooleanField(default = False, null = False)
is_active = models.BooleanField(default = True, null = False)
is_staff = models.BooleanField(default=False, null = False)
def save(self, *args, **kwargs):
error = False
try:
User.clean_fields(self)
except ValidationError as e:
#print 'ValidationError: %s' %(e)
error = True
if error == False:
super(User,self).save(*args, **kwargs)
def get_short_name():
return self.fname
然后我有一个管理类
from django.contrib import admin
from django.contrib.auth.models import Permission
from User.models import User
# Register your models here.
class UserAdmin(admin.ModelAdmin):
list_display = ('fname', 'lname', 'email')
search_fields =['User__email']
class Meta:
permissions = (
("search_users", "Can search"),)
admin.site.register(User, UserAdmin)
admin.site.register(Permission)
现在我首先尝试在管理页面上显示一个搜索框,允许我搜索我的用户以找到特定的搜索框。当我转到我的管理页面时,搜索框永远不会显示。它说我没有任何编辑任何内容的权限,这是问题所在吗?如果是这样,我如何向管理员添加权限?我试过(正如你在我的代码中看到的那样)没有优势。
答案 0 :(得分:0)
您的应用名称和用户模型均名为User
。这可能导致Python导入错误的东西。尝试将用户模型重命名为UserProfile
或类似的东西。