Opened 4 months ago

Closed 4 months ago

#35484 closed New feature (duplicate)

Enhances the flexibility of the Django admin interface by supporting custom user models more effectively.

Reported by: Mehul Talpada Owned by: nobody
Component: contrib.auth Version: 5.0
Severity: Normal Keywords: Admin panel, Password Change Form, Custom User
Cc: Mehul Talpada Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Issue:
In Django, when we create a custom user model and register it in admin.py, the change password form is not included by default. To add this functionality, we need to make several adjustments. Additionally, we cannot simply inherit the UserAdmin class from django.contrib.auth.admin because if we remove the username field, we must override fieldsets, list_display, search_fields, and ordering.

Contribution:
I have made a pull request that addresses this issue by:

Adding the USERNAME_FIELD to the UserAdmin class for automatic registration and form compatibility with custom user models.
Ensuring that custom user models (based on AbstractUser) do not require manual registration or model admin creation to include a change password form.
Updating the UserAdmin class to handle custom user models without requiring extensive overrides for common configurations.I have made a pull request that adds the USERNAME_FIELD to UserAdmin for automatic registration and form compatibility with custom user models. This update ensures that custom user models (based on AbstractUser) do not require manual registration or model admin creation to include a change password form.

In django if we made custom user model and register user model in admin.py. then we don't have change password form.
and to add this fucntionality we have to some changes as well we can not inherit the UserAdmin class becouse if we remove the username field then we have to overide fieldsets, list_display

Change History (2)

comment:1 by Mehul Talpada, 4 months ago

Summary: This commit enhances the flexibility of the Django admin interface by supporting custom user models more effectively.Enhances the flexibility of the Django admin interface by supporting custom user models more effectively.

comment:2 by Sarah Boyce, 4 months ago

Resolution: duplicate
Status: newclosed

Thank you for raising this ticket Mehul!

Looking at other tickets around a similar topic and it looks like this work (making the UserAdmin work for custom user models) is being tracked by #28608
Note that #29753 is perhaps more similar to this request and also being tracked in #28608.
When working on this, look into the previous work and discussions of #28608 and make sure they are incorporated 👍

Note: See TracTickets for help on using tickets.
Back to Top