Opened 12 days ago

Last modified 12 hours ago

#35742 assigned Cleanup/optimization

Apply UserAdmin add_form_template according to User model USERNAME_FIELD — at Version 2

Reported by: antoliny0919 Owned by:
Component: contrib.admin Version: 5.1
Severity: Normal Keywords: UserAdmin, add_form_template
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by antoliny0919)

Hello!! I made a ticket because there was something ambiguous on the Add page of the UserAdmin model.

The UserAdmin model customizes the ModelAdmin Add page with add_form_template variable.
And the template used as the value for that variable is admin/auth/user/add_form.html.

I felt this part was ambiguous in the add_form template.

...
{% block form_top %}
  {% if not is_popup %}
    <p>{% translate 'First, enter a username and password. Then, you’ll be able to edit more user options.' %}</p>
  {% else %}
    <p>{% translate "Enter a username and password." %}</p>
  {% endif %}
{% endblock %}
...

In the UserAdmin model, when a user uses a custom user model, USERNAME_FIELD allows a field other than username to be used.

However, in the above template, <p>{%translate 'First, enter a username and password. Then, you'll be able to edit more user options.'%}</p> This part is target at the default user provided by Django, so it is awkward because "username" is also seen when customizing USERNAME_FIELD using custom users.

Is this part using a static value because it is a ModelAdmin based on the User model provided by Django?

I added the method to the UserAdmin model and modified add_form.html to show the tag using the USERNAME_FIELD value.

I respect the great code from the Django maintainer and contributors. But I made a ticket out of my personal opinion that the code would be more curious and in a better way.

Thank you for reading it.

Change History (2)

comment:1 by antoliny0919, 12 days ago

Has patch: set
Last edited 10 days ago by antoliny0919 (previous) (diff)

comment:2 by antoliny0919, 11 days ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top