get_fieldsets destroys add user form

hi, when i use get_fieldsets, it destroy add user from.

from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.utils.translation import gettext_lazy as _
from django.contrib import admin
from .forms import User, UserChangeForm, UserCreationForm
from .models import User
 
 
class UserAdmin(BaseUserAdmin):
    ordering = ['username']
    add_form = UserCreationForm
    form = UserChangeForm
    model = User
    list_display = ['id', 'username', 'is_active', 'is_security', 'is_customer']
    list_display_links = ['id', 'username']
    list_filter = ['username', 'is_security', 'is_customer']
    def get_fieldsets(self, request, *args, **kwargs):
        if request.user.is_superuser:
            return (
                (None, {
                    'fields': (
                        'email', 'password', 'first_name', 'last_name', 'groups', 'is_active', 'is_superuser',
                        'is_staff', 'last_login', 'user_permissions',
                    ),
                }),
            )
        return (
            (None, {
                'fields': (
                    'first_name', 'last_name','password',
                )
            }),
        )
 
admin.site.register(User, UserAdmin)

can anyone came across this problem?

If you read the source for get_fieldsets in django.contrib.auth.admin.UserAdmin, you’ll see it doesn’t work like a typical get_fieldsets function. It checks to see if you’re creating a new User or editing an existing User and changes what it returns accordingly.

You probably need to add the same logic to your get_fieldsets function.