Opened 4 hours ago

Last modified 96 minutes ago

#36121 assigned New feature

Allow customization of password_change_form in the Django admin site

Reported by: Mohammadreza Eskandari Owned by: Mohammadreza Eskandari
Component: contrib.admin Version: 5.1
Severity: Normal Keywords: password_change, admin_site
Cc: Mohammadreza Eskandari Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mohammadreza Eskandari)

The Django admin site currently provides the ability to customize the login_form through the AdminSite.login_form attribute. However, no similar mechanism exists to customize the password_change_form used in the admin for password changes.

This inconsistency limits flexibility for developers who want to provide custom logic or fields for password changes in the admin interface. For example, a developer may want to enforce additional security checks, integrate password strength validation, or provide a more user-friendly design.

Proposed Solution:
Introduce a new attribute, AdminSite.password_change_form, which developers can override to specify a custom form for the password change functionality. This attribute would function similarly to AdminSite.login_form, allowing developers to define and register a custom form class.

Benefits:

  • Enhances consistency with existing AdminSite customization options.
  • Provides more flexibility for developers working with the Django admin site.
  • Simplifies the implementation of custom password change logic.

Example:

from django.contrib.admin import AdminSite
from myapp.forms import CustomPasswordChangeForm

class MyAdminSite(AdminSite):
    password_change_form = CustomPasswordChangeForm

Potential Backwards Compatibility Issues:
The proposed change should not introduce any breaking changes, as the default behavior would remain unchanged unless password_change_form is explicitly set.

My Contribution:
I have submitted a pull request which is available at https://github.com/django/django/pull/19081

Change History (2)

comment:1 by Mohammadreza Eskandari, 3 hours ago

Description: modified (diff)

comment:2 by Antoliny, 96 minutes ago

Owner: set to Mohammadreza Eskandari
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top