extend User Model for custom fields

49 views
Skip to first unread message

Antonio Sánchez

unread,
Mar 25, 2011, 9:04:36 AM3/25/11
to django...@googlegroups.com
hi! i have a question, which is the best option about extending user model??
here:
http://docs.djangoproject.com/en/1.2//topics/auth/#storing-additional-information-about-users
they say to create a manual OneToOneField between models and some more stuff,
but here:
http://docs.djangoproject.com/en/1.2//topics/db/models/#multi-table-inheritance
it says that with inheritance this 1:1 relationship is created automatically, both are in django docs

appart from this, i have read a lot ways, some people inherit, other use foreign key, ones redefines django's authentication backend other rewrites pre-save/save methods... :S ... so, which way do you think is better (some tutorial/blog post/something)?? thanks!

djjango’s authentication backend.

Calvin Spealman

unread,
Mar 25, 2011, 9:12:20 AM3/25/11
to django...@googlegroups.com, Antonio Sánchez
The auth app includes support to use a profile model, configured with
AUTH_PROFILE_MODULE in settings, which the docs show you how to use.
Yes you can use inheritance, but you might assume it is a good idea to
use what the auth app promotes.

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

--
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy

Antonio Sánchez

unread,
Mar 25, 2011, 10:26:46 AM3/25/11
to Django users
i have found this: http://digitaldreamer.net/blog/2010/12/8/custom-user-profile-and-extend-user-admin-django/
do you think its the correct way??

thanks for your reply!

On Mar 25, 2:12 pm, Calvin Spealman <ironfro...@gmail.com> wrote:
> The auth app includes support to use a profile model, configured with
> AUTH_PROFILE_MODULE in settings, which the docs show you how to use.
> Yes you can use inheritance, but you might assume it is a good idea to
> use what the auth app promotes.
>
>
>
> On Fri, Mar 25, 2011 at 9:04 AM, Antonio Sánchez <adonis28...@gmail.com> wrote:
>
> > hi! i have a question, which is the best option about extending user model??
> > here:
> >http://docs.djangoproject.com/en/1.2//topics/auth/#storing-additional...
> > they say to create a manual OneToOneField between models and some more stuff,
> > but here:
> >http://docs.djangoproject.com/en/1.2//topics/db/models/#multi-table-i...
> > it says that with inheritance this 1:1 relationship is created automatically, both are in django docs
>
> > appart from this, i have read a lot ways, some people inherit, other use foreign key, ones redefines django's authentication backend other rewrites pre-save/save methods... :S ... so, which way do you think is better (some tutorial/blog post/something)?? thanks!
>
> > djjango’s authentication backend.
>
> > --
> > You received this message because you are subscribed to the Google Groups "Django users" group.> To post to this group, send email todjang...@googlegroups.com.> To unsubscribe from this group, send email todjango-user...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.
>
> --
> Read my blog! I depend on your acceptance of my opinion! I am interesting!http://techblog.ironfroggy.com/

Andre Terra

unread,
Mar 25, 2011, 11:39:43 AM3/25/11
to django...@googlegroups.com, Antonio Sánchez
This is the correct way:

http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/



Sincerely,
Andre Terra

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.

Nick Serra

unread,
Mar 25, 2011, 4:16:51 PM3/25/11
to Django users
Andre's solution is out of date. Calvin is correct, use the user
profile model that is built into django auth. OP, the link you found
is correct.

On Mar 25, 11:39 am, Andre Terra <andrete...@gmail.com> wrote:
> This is the correct way:
>
> http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-m...
>
> Sincerely,
> Andre Terra
>
> On Fri, Mar 25, 2011 at 11:26 AM, Antonio Sánchez <adonis28...@gmail.com>wrote:
>
>
>
> > i have found this:
> >http://digitaldreamer.net/blog/2010/12/8/custom-user-profile-and-exte...

Mike Ramirez

unread,
Mar 25, 2011, 4:30:54 PM3/25/11
to django...@googlegroups.com
On Friday, March 25, 2011 01:16:51 pm Nick Serra wrote:
> Andre's solution is out of date. Calvin is correct, use the user
> profile model that is built into django auth. OP, the link you found
> is correct.
>
> >
> > http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-m...
> >
> > > > > here:
> > > > >http://docs.djangoproject.com/en/1.2//topics/auth/#storing-
additional-information-about-users

and:

http://docs.djangoproject.com/en/1.3/topics/auth/#storing-additional-
information-about-users

What's different about these pages, except that b-list goes into a bit more
detail?


Hint: Nothing.

But I don't think there is a "correct" way, just a recommended way. I use the
recommended way, but it's definately not the only way or 'better'. 'correct',
'better' in this case are subjective to the needs of the dev and/or project.

Mike.


--
Reality is just a convenient measure of complexity.
-- Alvy Ray Smith

Antonio Sánchez

unread,
Mar 26, 2011, 6:53:16 AM3/26/11
to Django users
Yeah sure, i should have used "recommended" word instead of correct.

The difference between link i wrote and b-list is that the last one
uses a foreign-key, while first uses one-to-one, and this is the way
is recommended in doc, so... I think i will follow that post
recommendations.

Thanks again!

p.d.: in this case, recommendation is not no use heritange, but, in
cases where i want to extend ANOTHER app (3rd apps), how do you do it?
using inheritange?

Derek

unread,
Mar 28, 2011, 2:40:29 AM3/28/11
to Django users
The b-list approach works just fine, whether you use a OneToOne or
ForeignKey (with unique=True).
Reply all
Reply to author
Forward
0 new messages