Hi Luan,

Thanks for the suggestion, but the change you've described won't work, for
two reasons.

Firstly, the call to get_user_model() will be parsed when the forms module
is loaded (because it's part of the Meta declaration). However, module load
order can't be guaranteed, so there will be ways to construct a project
where this form definition will break -- there's no way to know that the
User model has been loaded yet.

Secondly, the forms still hardcode the fact that the User has a "username"
field -- which is the fundamental constraint that having custom Users is
trying to break. Even if the User model *does* have a username field,
there's no guarantee that it matches the form constraints described by the
UserCreationForm -- your custom User might have different length or
character constraints, for example.

The decision to keep UserCreationForm and UserChangeForm hard coded as a
form on auth.User was deliberate, because the requirements for any specific
User model are very specific. Writing a UserCreationForm isn't *that* hard
(especially if you use ModelForm), so rather than try an make a truly
generic UserCreationForm, we decided to force end users to define their
own, based on their own requirements.

Yours,
Russ Magee %-)

On Sat, Feb 23, 2013 at 1:43 AM, <[email protected]> wrote:

> Hello guys,
>
> When I had to customize my users in Django 1.5 where UserProfile got
> deprecated,
> I found out I'd have to rewrite the UserCreationForm (contrib.auth), as
> described in docs[1].
>
> Is it really necessary to rewrite it all? What if the function
> get_user_model from contrib.auth was used instead of calling the auth User
> model directly? Wouldn't it work?
> That's how I imagine it [2]. UserChangeForm also has a "model = User". I
> believe it fits in the same case above.
>
> [1] https://docs.djangoproject.com/en/1.5/topics/auth/customizing/
> [2]
> https://github.com/LuanP/django/commit/a6ed3aa292f103ba193407dc96919adb17361f32
>
> Cheers,
> Luan.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-developers?hl=en
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to