On 8/23/2010 1:52 AM, adambossy wrote: > I'm helping build a social networking site which makes heavy use of > django built-in User model and its relationship to other Users on the > site. We created a UserProfile per the django documentation [http:// > docs.djangoproject.com/en/dev/topics/auth/#storing-additional- > information-about-users] that links to a single User object. Hence, > each time we make a database call involving a user, we retrieve the > UserProfile model via request.user.get_profile(), which occurs quite > frequently. > > This seems rather odd, considering the user is passed to our views by > default, yet has no useful information. I'm no django expert, but my > assumption is that this design decision was made to allow decoupled > apps to work together. Since we're basically writing everything in- > house (generic apps always have *just enough* discrepancies to what we > want to do that we end up rewriting them), perhaps we're not reaping > this benefit. My intuition tells me that we should have ignore > django.contrib.auth.models.User and created our own to which > everything else on our site relates. Thoughts? >
The usual practice is that described in the documentation, as far as I can tell. By retaining the User model you also retain the ability to use the standard authentication mechanism. If you decide you can do without that then knock yourself out, but (for example) the admin subsite expects that mechanism to be available by default. You can build your own authentication backend as described in http://docs.djangoproject.com/en/dev/topics/auth/#specifying-authentication- but you will see from there that the authenticate() method is expected to return a django.contrib.auth.models.User instance. The recommended one-to-one relationship between User and UserProfile allows you to ensure that there is only one profile per user. regards Steve -- DjangoCon US 2010 September 7-9 http://djangocon.us/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.