On Apr 22, 3:03 pm, Tom Evans <
tevans...@googlemail.com> wrote:
> On Thu, Apr 22, 2010 at 1:52 PM, derek <
gamesb...@gmail.com> wrote:
> > This thread:
> >
http://groups.google.com/group/django-users/browse_thread/thread/b303...
> > 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.contri...
>
> 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
Thanks Tom
I had thought I understood these concepts, but cannot see how to apply
them to the User specifically. That is why specific examples of code
always help (apart from the ones in the manual).
What would the code for "Register a different ModelAdmin for the
auth.User class" look like?
And can you expand further on this : "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." How would this be represented in code form?
(I appreciate I may seem obtuse here, but for some reason I can't
grasp these aspects of Django although everything else about it has
made perfect sense up to now.)
Thanks
Derek