[Django] #36121: Allow customization of password_change_form in the Django admin site

17 views
Skip to first unread message

Django

unread,
Jan 21, 2025, 4:31:05 AMJan 21
to django-...@googlegroups.com
#36121: Allow customization of password_change_form in the Django admin site
-------------------------------------+-------------------------------------
Reporter: mohammadrezaesk | Type: New
| feature
Status: new | Component:
| contrib.admin
Version: 5.1 | Severity: Normal
Keywords: password_change, | Triage Stage:
admin_site | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
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 am ready to submit a pull request. If the idea is accepted, I will
ensure the implementation adheres to Django's standards, including adding
documentation and tests where necessary.
--
Ticket URL: <https://code.djangoproject.com/ticket/36121>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 21, 2025, 5:20:25 AMJan 21
to django-...@googlegroups.com
#36121: Allow customization of password_change_form in the Django admin site
-------------------------------------+-------------------------------------
Reporter: Mohammadreza | Owner: (none)
Eskandari |
Type: New feature | Status: new
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution:
Keywords: password_change, | Triage Stage:
admin_site | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Mohammadreza Eskandari:

Old description:
New description:
**I have submitted a pull request which is available at
https://github.com/django/django/pull/19081

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36121#comment:1>

Django

unread,
Jan 21, 2025, 6:56:14 AMJan 21
to django-...@googlegroups.com
#36121: Allow customization of password_change_form in the Django admin site
-------------------------------------+-------------------------------------
Reporter: Mohammadreza | Owner:
Eskandari | Mohammadreza Eskandari
Type: New feature | Status: assigned
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution:
Keywords: password_change, | Triage Stage:
admin_site | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* owner: (none) => Mohammadreza Eskandari
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36121#comment:2>

Django

unread,
Jan 22, 2025, 3:03:37 PMJan 22
to django-...@googlegroups.com
#36121: Allow customization of password_change_form in the Django admin site
-------------------------------------+-------------------------------------
Reporter: Mohammadreza | Owner:
Eskandari | Mohammadreza Eskandari
Type: New feature | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: password_change | Triage Stage: Accepted
form, admin_site |
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* keywords: password_change, admin_site => password_change form,
admin_site
* needs_docs: 0 => 1
* needs_tests: 0 => 1
* stage: Unreviewed => Accepted
* version: 5.1 => dev

Comment:

Thank you Mohammadreza Eskandari for taking the time to create this
ticket.

Considering that we already have `password_change_template` and
`password_change_done_template` definitions in `AdminSite`, I'm inclined
to accept this ticket. But, I would need that a test project is shared so
you can showcase the concrete use case for this. Mohammadreza could you
please provide that?

Specifically for the PR, it would need tests and proper docs for:
1. A small release note in the 6.0.txt file.
2. A somehow complete example in the docs of overriding the forms to
better exemplify its value (to be part of `/ref/contrib/admin/`).
--
Ticket URL: <https://code.djangoproject.com/ticket/36121#comment:3>

Django

unread,
Jan 23, 2025, 4:04:28 PMJan 23
to django-...@googlegroups.com
#36121: Allow customization of password_change_form in the Django admin site
-------------------------------------+-------------------------------------
Reporter: Mohammadreza | Owner:
Eskandari | Mohammadreza Eskandari
Type: New feature | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: password_change | Triage Stage: Accepted
form, admin_site |
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mohammadreza Eskandari):

Hi Natalia

Thank you so much for accepting my ticket and considering the changes!

I’ve created a GitHub repository to demonstrate the changes I’ve made in
relation to this ticket. In this repo, you will find a test project with
the necessary customizations for overriding the password_change_form as
discussed.

link of repository: https://github.com/mohammadrezaesk/django-ticket-36121
-show-case

**PR changes:**
Additionally, I’ve added test cases to the PR to check for security-
related changes, and I’ve updated the release notes and documentation as
requested 🫡.

Regarding the documentation, when I checked the existing docs for the
login_form customization, I noticed there were no detailed examples
provided for similar attributes. So, I followed the same format as the
login_form example and avoided adding unnecessary text. This way, the
documentation remains consistent with the current structure, and the
example is clear and concise.

Feel free to check out the project and let me know if further adjustments
are needed!

Looking forward to your feedback.
--
Ticket URL: <https://code.djangoproject.com/ticket/36121#comment:4>

Django

unread,
Jan 23, 2025, 4:10:44 PMJan 23
to django-...@googlegroups.com
Replying to [comment:3 Natalia Bidart]:
> Thank you Mohammadreza Eskandari for taking the time to create this
ticket.
>
> Considering that we already have `password_change_template` and
`password_change_done_template` definitions in `AdminSite`, I'm inclined
to accept this ticket. But, I would need that a test project is shared so
you can showcase the concrete use case for this. Mohammadreza could you
please provide that?
>
> Specifically for the PR, it would need tests and proper docs for:
> 1. A small release note in the 6.0.txt file.
> 2. A somehow complete example in the docs of overriding the forms to
better exemplify its value (to be part of `/ref/contrib/admin/`).
--
Ticket URL: <https://code.djangoproject.com/ticket/36121#comment:5>

Django

unread,
Jan 23, 2025, 6:11:50 PMJan 23
to django-...@googlegroups.com
#36121: Allow customization of password_change_form in the Django admin site
-------------------------------------+-------------------------------------
Reporter: Mohammadreza | Owner:
Eskandari | Mohammadreza Eskandari
Type: New feature | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: password_change | Triage Stage: Accepted
form, admin_site |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* needs_docs: 1 => 0
* needs_tests: 1 => 0

Comment:

It seems like ticket owner are waiting for fellow's review, so I have
unset "Needs documentation" and "Patch needs improvement".
Additionally, I recommend this document for you.
[https://docs.djangoproject.com/en/dev/internals/contributing/writing-code
/submitting-patches/#patch-style contributing workflow detail docs]
--
Ticket URL: <https://code.djangoproject.com/ticket/36121#comment:6>

Django

unread,
Jan 24, 2025, 3:46:09 PMJan 24
to django-...@googlegroups.com
#36121: Allow customization of password_change_form in the Django admin site
-------------------------------------+-------------------------------------
Reporter: Mohammadreza | Owner:
Eskandari | Mohammadreza Eskandari
Type: New feature | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: password_change | Triage Stage: Accepted
form, admin_site |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mohammadreza Eskandari):

Hi Antoliny,

Thank you so much for your guidance and for recommending the contributing
workflow detail docs! This is my first contribution to Django, and I truly
appreciate the help and support from the community throughout the process.


Replying to [comment:6 Antoliny]:
> It seems like ticket owner are waiting for fellow's review, so I have
unset "Needs documentation" and "Patch needs improvement".
> Additionally, I recommend this document for you.
[https://docs.djangoproject.com/en/dev/internals/contributing/writing-code
/submitting-patches/#patch-style contributing workflow detail docs]
--
Ticket URL: <https://code.djangoproject.com/ticket/36121#comment:7>

Django

unread,
Jan 29, 2025, 10:38:12 AMJan 29
to django-...@googlegroups.com
#36121: Allow customization of password_change_form in the Django admin site
-------------------------------------+-------------------------------------
Reporter: Mohammadreza | Owner:
Eskandari | Mohammadreza Eskandari
Type: New feature | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: password_change | Triage Stage: Accepted
form, admin_site |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36121#comment:8>

Django

unread,
Jan 30, 2025, 4:52:43 AMJan 30
to django-...@googlegroups.com
#36121: Allow customization of password_change_form in the Django admin site
-------------------------------------+-------------------------------------
Reporter: Mohammadreza | Owner:
Eskandari | Mohammadreza Eskandari
Type: New feature | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: password_change | Triage Stage: Ready for
form, admin_site | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36121#comment:9>

Django

unread,
Jan 30, 2025, 6:19:17 AMJan 30
to django-...@googlegroups.com
#36121: Allow customization of password_change_form in the Django admin site
-------------------------------------+-------------------------------------
Reporter: Mohammadreza | Owner:
Eskandari | Mohammadreza Eskandari
Type: New feature | Status: closed
Component: contrib.admin | Version: dev
Severity: Normal | Resolution: fixed
Keywords: password_change | Triage Stage: Ready for
form, admin_site | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"12b9ef38b3ff7f5b8b24a5f42e8923fdb6db44bb" 12b9ef38]:
{{{#!CommitTicketReference repository=""
revision="12b9ef38b3ff7f5b8b24a5f42e8923fdb6db44bb"
Fixed #36121 -- Allowed customizing the admin site password change form.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36121#comment:10>

Django

unread,
Sep 5, 2025, 8:17:14 AM (5 days ago) Sep 5
to django-...@googlegroups.com
#36121: Allow customization of password_change_form in the Django admin site
-------------------------------------+-------------------------------------
Reporter: Mohammadreza | Owner:
Eskandari | Mohammadreza Eskandari
Type: New feature | Status: closed
Component: contrib.admin | Version: dev
Severity: Normal | Resolution: fixed
Keywords: password_change | Triage Stage: Ready for
form, admin_site | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"0ddbe12ea99a2dc1b757dc2015ba8bb6bfd9d653" 0ddbe12e]:
{{{#!CommitTicketReference repository=""
revision="0ddbe12ea99a2dc1b757dc2015ba8bb6bfd9d653"
Refs #36121 -- Fixed location of release note.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36121#comment:11>
Reply all
Reply to author
Forward
0 new messages