Saturday, July 14, 2012

Re: Extend user model: class inheritance or OneToOneField?

On 14-7-2012 0:18, sdonk wrote:

> I'm starting a new project and for the first time I need to extend the User
> model.

Important question: Why?

> I read the documentation and I googled a lot to try to figure out what is
> the best approach but I got confused.
>
> What's the the best approach?

Depends on the why. A site (as in a project) only allows one user
profile, so applications calling user.get_user_profile() cannot rely on
their version of the profile being returned. That's one important reason
not to follow the documentation recommendation.
Also, when subclassing you shall not set objects to UserManager. This
will make several queries fail in unexpected ways. Instead, set objects
to the default manager and provide a separate property for the user manager.
When you additionally need to add more information to Group and thus
subclass it, then things get complex real fast.
Having tried this exercise I've now decided to write my own auth package
all together.
--
Melvyn Sopacua


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate