i really cant find my problem.. but my problem is that i have something duplicated in my tuple


the error is :

ERRORS: <class ‘registerapp.admin.UserAdminConfig’>: (admin.E012) There are duplicate field(s) in ‘fieldsets[1][1]’. <class ‘registerapp.admin.UserAdminConfig’>: (admin.E012) There are duplicate field(s) in ‘fieldsets[2][1]’.

btw I have to inform that I have used mobileNumber as unique=True in my model

from django.contrib import admin
from registerapp.models import Members
from django.contrib.auth.admin import UserAdmin

class UserAdminConfig(UserAdmin):
    search_fields = ('email', 'name', 'mobileNumber',)
    list_filter = ('email', 'name', 'mobileNumber', 'nationalCode',)
    ordering = ('email',)
    list_display = ('email', 'familyName', 'mobileNumber', 'nationalCode', 'is_active', 'is_staff')
    fieldsets = (
        (None, {'fields': ('name', 'familyName')}),
        ('User information', {'fields': ('email', 'name', 'familyName', 'mobileNumber', 'password', 'nationalCode')}),
        ('Permissions', {'fields': ('is_staff', 'is_active', 'is_superuser', 'groups')}),


    add_fieldsets = (None, {
        'classes': ('wide',),
        'fields': ('email', 'name', 'familyName', 'mobileNumber', 'password', 'nationalCode')

admin.site.register(Members, UserAdminConfig)

my model

class customMemberManager(BaseUserManager):
    def create_user(self, email, mobileNumber, name, familyName, password, nationalCode, **other_fields):
        if not email:
            raise ValueError('YOU MUST ENTER VALID EMAIL')

        email = self.normalize_email(email)
        user = self.model(email=email, mobileNumber=mobileNumber, name=name, familyName=familyName, password=password,
                          nationalCode=nationalCode, **other_fields)
        return user

    def create_superuser(self, email, mobileNumber, name, familyName, password, nationalCode, **other_fields):
        other_fields.setdefault('is_staff', True)
        other_fields.setdefault('is_superuser', True)
        other_fields.setdefault('is_active', True)

        if other_fields.get('is_staff') is not True:
            raise ValueError('superuser must be is_staff set to True')
        if other_fields.get('is_superuser') is not True:
            raise ValueError('superuser must be is_superuser set to True')
        return self.create_user(email, mobileNumber, name, familyName, password, nationalCode, **other_fields)

class Members(AbstractBaseUser, PermissionsMixin):
    class Meta:
        verbose_name_plural = 'Members'

    name = models.CharField(max_length=50)
    familyName = models.CharField(max_length=50)
    email = models.EmailField(max_length=50)
    nationalCode = models.IntegerField(null=True)
    mobileNumber = models.IntegerField(null=True, unique=True)
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=False)
    is_superuser = models.BooleanField(default=False)
    objects = customMemberManager()

    USERNAME_FIELD = 'mobileNumber'
    REQUIRED_FIELDS = ['nationalCode', 'familyName', 'name', 'email']

    def __str__(self):
        return self.name.__str__()


As error say, you have duplicate fields in fieldsets.
First fieldset "None" has "name" and "familyName", second fieldset "User Information" has "name" and "familyName" again.

Try removing "name" and "familyName" from first or second fieldset

Answered By – backit

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published