On Tue, May 26, 2009 at 4:12 PM, neridaj <neri...@gmail.com> wrote:

>
> Is it only possible to access the methods of the associated User
> object, and not the attributes? Even though I can access the full name
> using get_full_name() I would still like to change the ordering to
> last_name i.e., ordering = ['last_name']. Do I need to make a new
> method that only only returns the last_name from within the User
> model, or manipulate the string returned from get_full_name()? I don't
> see why I can't just access the 'last_name' attribute of the
> associated user from within my user profile model.
>

It's extremely hard to follow what you are asking about due to the
top-posting of this thread, but if you are referring to the ordering you
have specified in this model from the first post to this thread:

 class Employee(models.Model):
       user = models.ForeignKey(User, unique=True)
       phone = PhoneNumberField()
       ssn = models.CharField(max_length=11)
       address = models.CharField(max_length=50)
       city = models.CharField(max_length=30)
       state = USStateField(default='WA')
       zip_code = models.CharField(max_length=10)

       def __unicode__(self):
               return self.user.full_name

       class Meta:
               ordering = ['last_name']

the problem is that the model Employee does not have a 'last_name'
attribute.  If you want to refer to the last_name attribute of the related
user, then you need to specify that, the same way you would if you were
filtering on last_name of the related user:

       class Meta:
               ordering = ['user__last_name']

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