Opened 5 weeks ago
Closed 3 weeks ago
#36121 closed New feature (fixed)
Allow customization of password_change_form in the Django admin site
Reported by: | Mohammadreza Eskandari | Owned by: | Mohammadreza Eskandari |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | password_change form, admin_site |
Cc: | Mohammadreza Eskandari | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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 (10)
comment:1 by , 5 weeks ago
Description: | modified (diff) |
---|
comment:2 by , 5 weeks ago
Owner: | set to |
---|---|
Status: | new → assigned |
follow-up: 5 comment:3 by , 5 weeks ago
Keywords: | form added |
---|---|
Needs documentation: | set |
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
Version: | 5.1 → dev |
comment:4 by , 4 weeks ago
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.
comment:5 by , 4 weeks ago
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.
Replying to Natalia Bidart:
Thank you Mohammadreza Eskandari for taking the time to create this ticket.
Considering that we already have
password_change_template
andpassword_change_done_template
definitions inAdminSite
, 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:
- A small release note in the 6.0.txt file.
- A somehow complete example in the docs of overriding the forms to better exemplify its value (to be part of
/ref/contrib/admin/
).
follow-up: 7 comment:6 by , 4 weeks ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
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. contributing workflow detail docs
comment:7 by , 4 weeks ago
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 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. contributing workflow detail docs
comment:8 by , 4 weeks ago
Patch needs improvement: | set |
---|
comment:9 by , 3 weeks ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Thank you Mohammadreza Eskandari for taking the time to create this ticket.
Considering that we already have
password_change_template
andpassword_change_done_template
definitions inAdminSite
, 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:
/ref/contrib/admin/
).