Thursday, April 22, 2010

Display first name and last name for user in dropdown lists in the Admin

This thread:
http://groups.google.com/group/django-users/browse_thread/thread/b303c1ce3e724407/d99ee36e031d7393
ends with the comment that "whatever string (actually unicode)
representation you want as constructed from the object attributes when
you bring an object via foreign key."

This is certainly true, and the example pointed to shows this:

class Choice(models.Model):
# ...
def __unicode__(self):
return self.choice

However, what does the equivalent code look like for the customizing
the built-in admin user (actually stored as "auth_user" in the
database), including the neccesary class statement line?

(Detailed issue: I have been using UserProfile to customize the User
for my application. However, all the links to the user in the other
models go direct to User and not UserProfile. Ideally, I'd like the
dropdown list for users to show the information returned by this:

def __unicode__(self):
return u'%s,%s (%s)' % (self.last_name, self.first_name,
self.fieldX)

where "fieldX' is a field added in the UserProfile. If someone can
show me the code to achieve this, it would be incredibly helpful...
and maybe I could learn something about users and profiles!)

Thanks
Derek

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate