On Thu, Apr 22, 2010 at 1:52 PM, derek <[email protected]> wrote: > 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 >
http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display Register a different ModelAdmin for the auth.User class, and define the fields you wish to display. Note that you can pass a callable as a field, and the callable will be called with the user instance, from which you can generate whatever content you like, even from the UserProfile. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

