Search code examples
djangodjango-usersdjango-auth-models

How to login to Django Admin panel with user I created in this panel? User model was extended


The model itself:

from django.db import models
from django.contrib.auth.models import AbstractUser

class UserModel(AbstractUser):
    class UserType(models.TextChoices):
        MANAGER = 'm', 'Manager'
        CUSTOMER = 'c', 'Customer'

    first_name = models.CharField(max_length=120)
    last_name = models.CharField(max_length=120)
    type = models.CharField(choices=UserType.choices, max_length=1)

USER_MODEL is registered in settings.py.

in admin.py it's registered as:

from django.contrib import admin
from .models import UserModel

admin.site.register(UserModel)

I can create new model in the panel with existing superuser I have. i.e. - it works. I can add new super users with manage.py and they appear in the same place in the panel. But later on I can't login with users I created in that panel.

saff status - checked.

The problem might be with passwords, because those created with createsuperuser shown hashed in the panel or I don't know even.

If I did smth completely wrong - let me know, I only need to extend users to have a couple of additional fields.

Django version 3.2


Solution

  • No worries django doesn't store raw passwords it always hash the password for security reasons, imagine someone hacked into your database people usually use the same password for all websites, not nice huh?!

    so try python manage.py changepassword <user_name> and write your new password

    and access the shell to check is_staff attr