Hello,

in the authentication documentation is written that the user profile
should be extended with a foreign key.

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

"If you'd like to store additional information related to your users,
Django provides a method to specify a site-specific related model --
termed a "user profile" -- for this purpose.

To make use of this feature, define a model with fields for the
additional information you'd like to store […] and also add a
ForeignKey from your model to the User model, specified with
unique=True to ensure only one instance of your model can be created
for each User."



If you look at the model documentation you can find this extract from
the text.

- http://docs.djangoproject.com/en/dev/ref/models/fields/#ref-models-fields

"A one-to-one relationship. Conceptually, this is similar to a
ForeignKey with unique=True, but the 'reverse' side of the relation
will directly return a single object.

This is most useful as the primary key of a model which "extends"
another model in some way […]"



Why should I use a ForeignKey if I want my user profile extended? If
the reverse side will return a single object, I could spare a little
bit of code, if I just write:
>>> "User.objects.get(username='Leon').avatar"
instead of
>>> "u = User.objects.get(username='Leon')"
>>> "UserProfileExtension.objects.get(user=u).avatar"



Comments are welcome!

-ld
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to