Changes between Initial Version and Version 2 of Ticket #8660


Ignore:
Timestamp:
08/28/08 17:52:22 (7 years ago)
Author:
mtredinnick
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #8660

    • Property Patch needs improvement unset
    • Property Needs documentation unset
    • Property Needs tests unset
    • Property Triage Stage changed from Unreviewed to Accepted
  • Ticket #8660 – Description

    initial v2  
    1 When you use the User.get_profile() method to fetch a profile object, it doesn't pre-populate profile's user attribute. This results in unnecessary DB queries when you go from User -> UserProfile and then later go from UserProfile -> User. This is actually a fairly common use case because people tend to attach methods that "extend" the user object in UserProfile, since they can't directly extend User.
     1When you use the User.get_profile() method to fetch a profile object, it doesn't pre-populate profile's user attribute. This results in unnecessary DB queries when you go from User -> `UserProfile` and then later go from `UserProfile` -> `User`. This is actually a fairly common use case because people tend to attach methods that "extend" the user object in UserProfile, since they can't directly extend User.
    22
    3 For example, if you create a full_name() method on UserProfile that returns '%s %s' % (self.user.first_name, self.user.last_name), then in your templates, you do {{ User.get_profile.full_name }}, you end up doing two DB queries when only one in necessary.
     3For example, if you create a `full_name()` method on `UserProfile` that returns {{{'%s %s' % (self.user.first_name, self.user.last_name)}}}, then in your templates, you do {{{ {{ User.get_profile.full_name }} }}}, you end up doing two DB queries when only one in necessary.
    44
    55The solution seems simple enough since the profile's User object must be called `user`. In django/contrib/auth/models.py a one liner after fetching the profile should do the trick:
Back to Top