Home > Mobile >  Django admin site user password change
Django admin site user password change

Time:12-05

Django admin site used to have a form to change the password for a user that wasn't the logged in user. You would look at the user's update page, and by the password field, there was a change password link. You would click it, and it would take you to a different page for changing the password. I used to take advantage of that page to allow changing of a user's password, without having to open the admin. In Django 4, it seems to now be missing. In fact, I can't figure out how one would change a user's password other than their own, without writing my own view.

I have 2 questions:

  1. Is there a way in the admin site now to change a different user's password?
  2. If this view is gone, what is now the best way for a superuser to have a view that can change passwords for a user?

Edit: This is what I see. There is no link to change the password where there used to be. enter image description here

CodePudding user response:

Are you sure you have checked it right? When you select an user it appears by default in the upper part, just after some semi-blinded parameters of the password.

enter image description here

CodePudding user response:

The problem was when I am using AbstractBaseUser, and the admin site registration I was using admin.ModelAdmin instead of UserAdmin.

from django.contrib.auth import get_user_model
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin


class EmployeeAdmin(UserAdmin):
    ordering = ['email', ]
    list_display = ['email', ]
    fieldsets = (
        (None, {'fields': ('email', 'password')}),
        ('Info', {'fields': ('first_name', 'last_name', 'phone',)}),
        ('Address', {'fields': ('address', 'city', 'state', 'zip_code')}),
        ('Schedule', {'fields': ('time_off',)}),
        ('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser',
                                    'groups', 'user_permissions')}),
        ('Important dates', {'fields': ('last_login', 'date_joined')}),
    )
    add_fieldsets = (
        ("User Details", {'fields': ('email', 'password1', 'password2')}),
        ("Permission", {'fields': ('is_active', 'is_staff', 'is_admin')}),
    )


admin.site.register(get_user_model(), EmployeeAdmin)
  • Related