Thanks Karen

I am slightly embarrassed with this one, You are correct that variant
works, the reason I thought it was not working is because the
User.first_name fields were empty and they were showing as blanks.

:)



On Jul 13, 3:54 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Mon, Jul 13, 2009 at 9:28 AM, wickass <wick...@gmail.com> wrote:
>
> > Hi Django users
>
> > I have only been using python& django for about a week, so please
> > excuse me if this question sounds stupid.
>
> > Basically I have a model which extends the users model via a OneToOne
> > relationship like so:
>
> > class AgentProfile(models.Model):
> >        user =          models.OneToOneField(User)
> >        company =       models.ForeignKey(Company)
> >        is_admin =      models.BooleanField()
> >        phone   =       models.CharField(max_length=15)
> >        fax     =       models.CharField(max_length=15)
>
> > However my chanlenge  is that in the admin application on the Agent
> > profile list all profiles are displayed as "AgentProfile object"
> > Now I understand that I have to define a __unicode__ method in order
> > to generate the object "name"(excuse the terminology). However in this
> > instance I would like to display the first_name from the user object
> > but I cant seem to get it to work.
>
> > I have tried:
>
> > def __unicode__(self):
> >                return self.user.first_name
>
> This variant is correct.  If you are still getting "AgentProfile object"
> after including this __unicode__ method in your model either you have not
> indented __unicode__ properly within the model class definition (it needs to
> be indented just as the field definitions are) or you have not reloaded the
> changed code in whatever method you are using to test the behavior.
>
> Karen
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to