thanks... i totally blanked as to where i was making the mistake. On Saturday, March 9, 2013 3:39:06 AM UTC-5, Atul Bhouraskar wrote: > > > I'll try to answer your second question: > > On Saturday, 9 March 2013 16:07:46 UTC+11, jayhalleaux wrote: >> >> <snip> >> > > >> 2. Accessing user profile data from a session. >> >> Example: >> >> models.py >> >> from django.contrib.auth.models import User >> >> class UserProfile(models.Model): >> >> user = models.ForeignKey(User, unique=True) >> timestamp = models.DateTimeField(auto_now_add=True) >> >> >> So in the above example if I get the User object from a session how do I >> get the session data. >> Per the documentation it looks like it should be: >> >> user = request.user >> >> timestamp = user.userprofile.timestamp >> >> >> I get that user does not have userprofile attribute. >> >> Hopefully someone can help... >> >> > user.userprofile will only work if you have a OneToOneField rather than > ForeignKey (which is a many-to-one relationship) in the UserProfile model > pointing to User. > > When you have a ForeignKey, the user object will instead have > user.userprofile_set which is a manager, so you could do > user.userprofile_set.all() to get all the profiles for this user. This is > probably not what you want so use a OneToOneField instead. > > Cheers, > > Atul >
-- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.

