On Mon, Apr 13, 2009 at 8:55 PM, James Bennett <[email protected]> wrote:
> It's true you *might* want to do it for any particular model, but the
> specific case of user profiles is such a common situation that it
> seems a shame to require everybody to come up with their own system
> and their own helpers and such. That's why Django has a standard API
> for handling user profiles.

You don't need to come up with helpers--OneToOneField automatically
creates the only helper this provides, in a way that (unlike
get_profile()) is consistent with all other model relationships.  It's
standardizing how to get to something while leaving that something
completely undefined, so you can't actually do much of anything with
it except stuff like auto-generated forms.  It just seems like a
narrowly useful special case.

> Well, the thing is that Django's had this API for years now, and
> people are familiar with it; while I'm sure it's possible to come up
> with other options which may or may not be "clearer", get_profile()
> has the advantage of already being a known, standard idiom in Django,
> which means people are more likely to recognize it and know what your
> code is doing than if you come up with your own system.

If someone can't instantly understand that "user.profile" refers to
the user's profile, they're already in trouble.  :)

Anyhow, even if it seems like a funny special case to me, it's
probably a total of twenty lines of code in auth, so it's harmless.  I
just wanted to know if there was some deeper design concept behind it.

Also, it's not mutually exclusive with accessing the profile
directly--is there any reason the docs shouldn't recommend
OneToOneField instead of ForeignKey for the profile's user field?
It's a better fit; this seems like a relic from before OneToOneField
was stable.  
http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users

-- 
Glenn Maynard

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

Reply via email to