Alex,

I managed to get it to work, and the column is even sortable! Thanks
for your help.

Here's my code for reference for anyone else who comes across this
post:

class UserAdmin(admin.ModelAdmin):

    def display_profile_status(self, obj):
        profile = obj.myprofile_set.all()
        if len(profile) > 0:
            return "%s" % profile[0].get_status_display()
        else:
            return "Nada"
    display_profile_status.short_description = 'Status'
    display_profile_status.allow_tags = True
    display_profile_status.admin_order_field = 'myprofile__status'

    inlines = [MyProfileInline]
    list_display = ('username',
                    'first_name',
                    'last_name',
                    'email',
                    'is_active',
                    'display_profile_status',
                    )


On Feb 16, 4:15 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> On Mon, Feb 16, 2009 at 7:13 PM, Kevin Audleman 
> <kevin.audle...@gmail.com>wrote:
>
>
>
>
>
> > Alex,
>
> > I feel like I'm one step closer to getting this to work. From the
> > documentation you sent my way, it seems like what I would do would be
> > to create a method on the User object which will span the relationship
> > and grab the value:,
>
> > def get_payment_status(self):
> >    return self.myprofile_set.all()[0].payment_status
>
> > However I am working with the core User object which I didn't write.
> > Am I SOL, or is there some way I can do this.
>
> > Thanks,
> > Kevin
>
> > On Feb 16, 4:02 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> > > On Mon, Feb 16, 2009 at 6:59 PM, Kevin Audleman <
> > kevin.audle...@gmail.com>wrote:
>
> > > > Thanks!
>
> > > > I've got my new User display going and another question has come up.
> > > > In the related MyProfile object, I've got a field called
> > > > payment_status. It's important for my client to be able to quickly
> > > > view a list of users with a payment_status of 'Unpaid.' Is there a way
> > > > to add a related field to the list_display or list_filter sets for the
> > > > User object?
>
> > > > Cheers,
> > > > Kevin
>
> > > > On Feb 16, 3:45 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> > > > > On Mon, Feb 16, 2009 at 6:27 PM, Kevin Audleman <
> > > > kevin.audle...@gmail.com>wrote:
>
> > > > > > I've created a custom profile per the instructions in chapter 12 of
> > > > > > the book to give my user's fields like address1, address2, etc.
> > > > > > Currently when I log in to the admin and want to update a user, I
> > have
> > > > > > to go to two separate pages: the User page to update core user
> > fields,
> > > > > > and the Profile page to update fields in the profiles.
>
> > > > > > I would like to overwrite the ModelAdmin for the User object and
> > > > > > inline the Profile object so that all fields for a user can be
> > edited
> > > > > > from one page. However django is throwing an error when I try to do
> > > > > > so:
>
> > > > > > AlreadyRegistered at /admin/
> > > > > > The model User is already registered
>
> > > > > > Here's the code:
>
> > > > > > class ProfileInline(admin.TabularInline):
> > > > > >    model = MyProfile
>
> > > > > > class UserAdmin(admin.ModelAdmin):
> > > > > >    list_display = ('username', 'email', 'first_name', 'last_name',
> > > > > > 'is_staff')
> > > > > >    list_filter = ('is_staff', 'is_superuser')
> > > > > >    inlines = [ProfileInline]
>
> > > > > > admin.site.register(User, UserAdmin)
>
> > > > > > Is there a way to do this?
>
> > > > > > Thanks,
> > > > > > Kevin Audleman
>
> > > > > Yes just do admin.site.unregister(User) before registering yours.
>
> > > > > Alex
>
> > > > > --
> > > > > "I disapprove of what you say, but I will defend to the death your
> > right
> > > > to
> > > > > say it." --Voltaire
> > > > > "The people's good is the highest law."--Cicero
>
> > > You can add it to the list_display by creating a method on the model for
> > it(http://docs.djangoproject.com/en/dev/ref/contrib/admin/#list-display)
> > and
> > > perhaps use the boolean option to make it more obvious.  Right now you
> > can't
> > > actually use related fields in list_filter:
> >http://code.djangoproject.com/ticket/3400
>
> > > Alex
>
> > > --
> > > "I disapprove of what you say, but I will defend to the death your right
> > to
> > > say it." --Voltaire
> > > "The people's good is the highest law."--Cicero
>
> You can also just write a method on the ModelAdmin itself, as the examples
> show.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~---------~--~----~------------~-------~--~----~
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