You can customize the OpenWISP Users admin interface using two methods:
1. Monkey Patching (For small changes)
Use this to add fields to existing forms. OpenWISP provides helper functions to make this easier:
usermodel_add_form: Adds fields to the "Add user" form.usermodel_change_form: Adds fields to the "Change user" profile section.usermodel_list_and_search: Makes a field searchable and adds it to the user list view.
2. Inheriting Admin Classes (For significant changes)
Unregister the base OpenWISP admin classes and register your own custom classes that inherit from them. Use swapper.load_model to retrieve the correct models.
# Method 2: Inheriting Admin Classes
from django.contrib import admin
from openwisp_users.admin import (
UserAdmin as BaseUserAdmin,
GroupAdmin as BaseGroupAdmin,
OrganizationAdmin as BaseOrganizationAdmin,
OrganizationOwnerAdmin as BaseOrganizationOwnerAdmin,
OrganizationUserAdmin as BaseOrganizationUserAdmin,
)
from swapper import load_model
from django.contrib.auth import get_user_model
Group = load_model("openwisp_users", "Group")
Organization = load_model("openwisp_users", "Organization")
OrganizationOwner = load_model("openwisp_users", "OrganizationOwner")
OrganizationUser = load_model("openwisp_users", "OrganizationUser")
User = get_user_model()
admin.site.unregister(Group)
admin.site.unregister(Organization)
admin.site.unregister(OrganizationOwner)
admin.site.unregister(OrganizationUser)
admin.site.unregister(User)
@admin.register(Group)
class GroupAdmin(BaseGroupAdmin):
pass
@admin.register(User)
class UserAdmin(BaseUserAdmin):
pass