Home > Mobile >  Not able to Login once user has been created in Django admin
Not able to Login once user has been created in Django admin

Time:12-27

I am able to create the user with permissions and groups. But I am not able to login with the created user in django admin.Creation of the user and permissions

CodePudding user response:

For a user to be able to login in django admin portal, is_staff field needs to be checked/marked as true.

CodePudding user response:

At first you should set user as is_staff and is_superuser

Then you can login with the account.

In addition, you can change the appearance of django admin with code below:

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import Group
from .models import User
# Register your models here.

class CustomUserAdmin(UserAdmin):
    fieldsets  = (
        ('Login Details', {
            'fields': ('username', 'password')
        }),

        ('Informations', {
            'fields': ('first_name', 'last_name', 'email','phonenumber')
        }),

        ('Permissions', {
            'fields': (
                'is_active',
                'is_staff',
                'is_superuser',
                'groups',
                'user_permissions'
            )
        }),
    )
    add_fieldsets = (
        ('Login Details', {
            'fields': ('username', 'password1', 'password2','phonenumber')
        }),
    )

admin.site.register(User, CustomUserAdmin)
  • Related