Opened 8 months ago

Closed 5 months ago

#28608 closed Cleanup/optimization (fixed)

Allow UserCreationForm and UserChangeForm to work with custom user models

Reported by: Rômulo Collopy Owned by: shangdahao
Component: contrib.auth Version: master
Severity: Normal Keywords: user, custom user, auth
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

class UserChangeForm(forms.ModelForm):
    # ...
    class Meta:
        model = User

and

class UserCreationForm(forms.ModelForm):
    class Meta:
        model = User

could use UserModel instead of User. It is already defined in https://github.com/django/django/blob/01c6a3e227b645e8dea97e9befecd23d1d3b8581/django/contrib/auth/forms.py#L20 and is used in other forms of the same package.

This would allow Django Registration and other packages that use these forms to work out of the box. And it would allow using them with no need to rewitte as specified at https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#custom-users-and-the-built-in-auth-forms

Attachments (1)

patch.diff (2.2 KB) - added by Rômulo Collopy 8 months ago.
patch

Download all attachments as: .zip

Change History (5)

Changed 8 months ago by Rômulo Collopy

Attachment: patch.diff added

patch

comment:1 Changed 8 months ago by Tim Graham

Patch needs improvement: set
Summary: UserCreationForm and UserChangeForm model using get_user_modelAllow UserCreationForm and UserChangeForm to work with custom user models

This is a continuation of #19353.

comment:2 Changed 8 months ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:3 Changed 6 months ago by shangdahao

Owner: changed from nobody to shangdahao
Patch needs improvement: unset
Status: newassigned

Since This ticket is related to ticket 28757, I made the changes for this ticket and ticket 28757 in the same commit.

PR

comment:4 Changed 5 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 3333d93:

Fixed #28757 -- Allowed using contrib.auth forms without installing contrib.auth.

Also fixed #28608 -- Allowed UserCreationForm and UserChangeForm to
work with custom user models.

Thanks Sagar Chalise and Rômulo Collopy for reports, and Tim Graham
and Tim Martin for reviews.

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