Reputation: 573
is_staff is defined as boolean field but its checkbox is not visible in the admin page. But is_admin is visible and it can be changed.
I can't able to make changes to that field using 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']
Upvotes: 1
Views: 1363
Reputation:
You can edit the User admin in admin.py by importing and inheriting from it. Here's an example:
# 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)
Upvotes: 1