# Django: How to create superuser with custom fields?

**URL:** <https://forum.djangoproject.com/t/django-how-to-create-superuser-with-custom-fields/14390>\
**Category:** Forms & APIs\
**Created:** [June 20, 2022, 10:22am UTC](https://forum.djangoproject.com/t/django-how-to-create-superuser-with-custom-fields/14390 "2022-06-20T10:22:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![khaw235](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/khaw235/32/6372_2.png) [@khaw235](https://forum.djangoproject.com/u/khaw235)\
**Post date:** [June 20, 2022, 10:22am UTC](https://forum.djangoproject.com/t/django-how-to-create-superuser-with-custom-fields/14390/1 "2022-06-20T10:22:20Z")

</div>

Hi there, I have a custom `User` model in my `models.py` and custom `UserManager` as well. My custom `User` model has `username` field with changed name to `login` and same is updated in `UserManager` as well. Everything goes fine, but when I try to create superuser using command `python manage.py createsuperuser`, it asks for `login` but it does not ask for `email` which at the end gives me this error:

```auto
TypeError: UserManager.create_superuser() missing 1 required positional argument: 'email'

```

My custom `User` model is:

```auto
class User(AbstractBaseUser, PermissionsMixin):
    login = models.CharField(max_length=254, unique=True)
    email = models.EmailField(max_length=254, unique=True)
    first_name = models.CharField(max_length=254, null=True, blank=True)
    last_name = models.CharField(max_length=254, null=True, blank=True)
    is_staff = models.BooleanField(default=False)
    is_admin = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    last_login = models.DateTimeField(null=True, blank=True)
    date_joined = models.DateTimeField(auto_now_add=True)
    
    USERNAME_FIELD = 'login'
    EMAIL_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = UserManager()

    def get_absolute_url(self):
        return "/users/%i/" % (self.pk)

```

My custom `UserManager` is:

```auto
class UserManager(BaseUserManager):
    def _create_user(self, login, email, password, is_staff, is_admin, **extra_fields):
        if not email:
            raise ValueError('Users must have an email address')

        now = timezone.now()
        email = self.normalize_email(email)

        user = self.model(
            login=login,
            email=email,
            is_staff=is_staff,
            is_active=True,
            is_admin=is_admin,
            last_login=now,
            date_joined=now, 
            **extra_fields
        )

        user.set_password(password)
        user.save(using=self._db)

        return user

    def create_user(self, login, email, password, **extra_fields):
        user = self._create_user(login, email, password, False, False, **extra_fields)
        user.save(using=self._db)
        
        return user

    def create_superuser(self, login, email, password, **extra_fields):
        user=self._create_user(login, email, password, True, True, **extra_fields)

        return user

```

and in `admin.py` I have:

```auto
class UserAdmin(BaseUserAdmin):
    fieldsets = (
        (None, {'fields': ('login', 'email', 'password', 'first_name', 'last_name', 'last_login')}),
        ('Permissions', {'fields': (
            'is_active', 
            'is_staff', 
            'is_admin',
            'groups', 
            'user_permissions',
        )}),
    )
    add_fieldsets = (
        (
            None,
            {
                'classes': ('wide',),
                'fields': ('login', 'email', 'password1', 'password2')
            }
        ),
    )

    list_display = ('login', 'email', 'first_name', 'last_name', 'is_admin', 'last_login')
    list_filter = ('is_staff', 'is_admin', 'is_active', 'groups')
    search_fields = ('email', 'login',)
    ordering = ('email', 'login',)
    filter_horizontal = ('groups', 'user_permissions',)

```

Any help will be appreciated.

---

<div class="post-metadata">

**Author:** ![khaw235](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/khaw235/32/6372_2.png) [@khaw235](https://forum.djangoproject.com/u/khaw235)\
**Post date:** [June 20, 2022, 10:53am UTC](https://forum.djangoproject.com/t/django-how-to-create-superuser-with-custom-fields/14390/2 "2022-06-20T10:53:24Z")

</div>

@KenWhitesell any suggestions??

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 20, 2022, 10:58am UTC](https://forum.djangoproject.com/t/django-how-to-create-superuser-with-custom-fields/14390/3 "2022-06-20T10:58:04Z")

</div>

See the docs for [Customizing authentication in Django | Django documentation | Django](https://docs.djangoproject.com/en/4.0/topics/auth/customizing/#specifying-a-custom-user-model)

---

<div class="post-metadata">

**Author:** ![khaw235](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/khaw235/32/6372_2.png) [@khaw235](https://forum.djangoproject.com/u/khaw235)\
**Post date:** [June 20, 2022, 11:38am UTC](https://forum.djangoproject.com/t/django-how-to-create-superuser-with-custom-fields/14390/4 "2022-06-20T11:38:38Z")

</div>

@KenWhitesell thanks for the guideline.
