Changing the group of a model in Django Admin
I actually had to combine what both Mohammad and NeErAj suggested.
When I tried to move Groups
to the Authorization
section, which is an app containing a custom User
model, it created duplicates of the Groups. Django still wanted to insert the default auth_group
which I couldn't figure out how to get rid of.
# ./models.py
from django.contrib.auth.models import Group
class Group(Group):
pass
class Meta:
app_label = 'authentication'
# ./admin.py
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User, SecurityQuestions, Group
admin.site.register(User, UserAdmin)
admin.site.register(SecurityQuestions)
admin.site.register(Group)
AUTHORIZATION
-------------
Groups
Security Questions
Users
AUTHORIZATION AND AUTHENTICATION
--------------------------------
Groups
Since I was using a custom User
model, I figured it would be easier to move them to app_label = 'auth'
. That way I wouldn't have to fight with the default auth_group
. Ended up doing the following:
# ./models.py
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
...
class Meta:
db_table = 'Users'
class SecurityQuestions(models.Model):
...
class Meta:
app_label = 'auth'
db_table = 'Security_Questions'
verbose_name = 'Security Question'
verbose_name_plural = 'Security Questions'
class ProxyUser(User):
pass
class Meta:
app_label = 'auth'
proxy = True
verbose_name = 'User'
verbose_name_plural = 'Users'
# ./admin.py
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User, SecurityQuestions, ProxyUser
admin.site.register(ProxyUser, UserAdmin)
admin.site.register(SecurityQuestions)
This got everything to look like:
AUTHORIZATION AND AUTHENTICATION
--------------------------------
Groups
Security Questions
Users