On 06/06/06 17:11, Todd O'Bryan wrote:
> On Jun 6, 2006, at 11:03 AM, Adrian Holovaty wrote:
> 
>>
>> On 6/6/06, Todd O'Bryan <[EMAIL PROTECTED]> wrote:
>>> Here's the problem: How do I get to those in a template? I know
>>> there's only one UserInfo object per User object, and ideally I'd
>>> like to type something like
>>>
>>> {{ user.userinfo.formalName }}
>>>
>>> in the template, but this doesn't work because userinfo is actually
>>> userinfo_set and I'd need to get the first element of that. I don't
>>> think that's possible in the templating language, but I'd be happy to
>>> be wrong.
>>
>> Get happy! :)
>>
>> {{ user.userinfo_set.0.formalName }}
>>
> 
> Why is it that you can't find stuff until after you send an email  
> asking about it?
> 
> I actually implemented a context processor, added a  
> TEMPLATE_CONTEXT_PROCESSORS to my settings.py and then noticed the  
> line I had missed about list lookup. (Actually, to slightly  
> complicate things, I tried user.userinfo_set[0].formalName first, but  
> that's another story.)
> 
> Thanks. I'll just go over here in the corner and play by myself.
> Todd
> 

Wouldn't that be a use case for djangos built in (but hardly documented)
AUTH_PROFILE_MODULE setting?

e.g.

settings.py: ----------

AUTH_PROFILE_MODULE = 'common.UserProfile'


myproject.common.models.py: ----------

class UserProfile(models.Model):
     user = models.ForeignKey(User)
     site = models.ForeignKey(Site, default=settings.SITE_ID, blank=True)
     nick = models.CharField(maxlength=32, blank=True, null=True)

     def informalName(self):
         return self.nick

     def formalName(self):
         return '%s %s' % (self.user.first_name, self.user.last_name)
     ...


And then in views:

request.user.get_profile().formalName()

or in templates:

{{ user.get_profile.formalName }}



--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to