[Django] #20657: Have UserChangeForm and UserCreationForm utilize get_user_model()

36 views
Skip to first unread message

Django

unread,
Jun 26, 2013, 4:43:43 AM6/26/13
to django-...@googlegroups.com
#20657: Have UserChangeForm and UserCreationForm utilize get_user_model()
--------------------------------------+--------------------
Reporter: ChocolateCookies | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Uncategorized | Version: 1.5
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
While I was trying to re-use the creation form for the admin interface
with my custom User model (derived from {{{AbstractUser}}}), I stumbled
upon an issue, namely I couldn't re-use it. I might have thought of a
solution, but it's probably not very elegant.

In {{{contrib.auth.forms}}} the model meta property for
{{{UserChangeForm}}} is User, but in for example AuthenticationForm, the
method {{{get_user_model}}} is utilized. Consequently I cannot use the
form, because this class imports auth.User instead of my own User model.
Is this on purpose, or would it be possible to extend AUTH_USER_MODEL to
the creation and change forms?

I would say it is only possible if a custom User model is derived from
{{{AbstractUser}}}, as opposed to {{{AbstractBaseUser}}}
([https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#specifying-a
-custom-user-model Like the Django docs suggest]). {{{AbstractUser}}}
guarantees the fields that these forms use (username, email), while
{{{AbstractBaseUser}}} doesn't. Although that takes away a lot of the
flexibility of specifying a custom User model, so maybe there's a middle
ground somewhere.

contrib/auth/forms.py:
{{{
class UserChangeForm(forms.ModelForm):
...
class Meta:
model = User
...
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20657>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 26, 2013, 5:01:06 AM6/26/13
to django-...@googlegroups.com
#20657: Have UserChangeForm and UserCreationForm utilize get_user_model()
-------------------------------------+-------------------------------------
Reporter: ChocolateCookies | Owner: nobody
Type: | Status: closed
Cleanup/optimization | Version: 1.5
Component: Uncategorized | Resolution: duplicate
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bmispelon):

* status: new => closed
* needs_better_patch: => 0
* resolution: => duplicate
* needs_tests: => 0
* needs_docs: => 0


Comment:

Correct me if I'm wrong, but I believe this is a duplicate of #19353.

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

Reply all
Reply to author
Forward
0 new messages