I cannot seem to get Groups to work with the Custom User Model. In the admin panel attached is the view. Its missing the box on the left with the assignment of adding and remove groups. I’ve tried checking and even unregistered and reregistered in the admin.py view. Codes below for my custom user class and admin. Code works for normal user logging in etc and for admin but i want the groups assignment to work which is just not working . Any help much apprecaited as i seem to be hitting a wall
class UserAdmin2(BaseUserAdmin):
# The forms to add and change user instances
form = UserAdminChangeForm
add_form = UserAdminCreationForm
# The fields to be used in displaying the User model.
# These override the definitions on the base UserAdmin
# that reference specific fields on auth.User.
list_display = ['email', 'admin','organisation','disipline']
list_filter = ['admin']
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Personal info', {'fields': ('fullname','organisation','disipline','subdisipline','designation','expiration')}),
('Permissions', {'fields': ('is_active','admin','staff','is_superuser','groups','user_permissions')}),
)
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
# overrides get_fieldsets to use this attribute when creating a user.
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('email', 'password', 'password_2')}
),
)
search_fields = ['email']
ordering = ['email']
filter_horizontal = ()
admin.site.register(CustomUser,UserAdmin2)
class CustomUser(AbstractBaseUser,PermissionsMixin):
email = models.EmailField(max_length=254, unique=True)
fullname = models.CharField(max_length=254, null=True)
disipline = models.CharField(max_length=254, blank=False, null=True)
subdisipline = models.CharField(max_length=254, blank=False, null=True)
organisation = models.CharField(max_length=254, blank=False, null=True)
designation = models.CharField(max_length=254, blank=True, null=True)
signature = models.CharField(max_length=100, blank=True, null=True)
expiration = models.DateTimeField(null=True)
is_active = models.BooleanField(default=True) #according to django contrib doc, is_active returned here
admin = models.BooleanField(default=False)
staff = models.BooleanField(default=True)
objects = UserManager()
mdlSetGetField = mgrSetGetfields()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['fullname','disipline']
def __str__(self):
return self.email
def get_full_name(self):
return self.fullname
def get_short_name(self):
return self.fullname
@property
def is_staff(self):
return self.staff
def is_admin(self):
#"Is the user a member of staff?"
# Simplest possible answer: All admins are staff
return self.admin
#def is_active(self): #after referring to django contrib docs, this does not work
#"Is the user a member of staff?"
# Simplest possible answer: All admins are staff
# return self.active
def has_perm(self, perm, obj=None):
"Does the user have a specific permission?"
# Simplest possible answer: Yes, always
return True
def has_module_perms(self, app_label):
#"Does the user have permissions to view the app `app_label`?"
# Simplest possible answer: Yes, always
return True
#changed active to is_active