1

I have a User model (stock django), linked with a UserProfile via a OneToOneField. Is it possible to display data from the UserProfile in the admin, when displaying users in tabular view?

I am doing:

class UserAdmin(UserAdmin):
    inlines = (UserprofileInline,)
    list_display = (
        'username', 'email', 'first_name', 'last_name', 'is_staff'
    )


# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)

How can I extend the list_display parameter to specify fields belonging to the UserProfile?

blueFast
  • 41,341
  • 63
  • 198
  • 344

2 Answers2

1

For example if you have an address field in UserProfile model then you can do like this

class UserAdmin(UserAdmin):
    inlines = (UserprofileInline,)
    list_display = (
        'username', 'email', 'first_name', 'last_name', 'is_staff','address'
    )

    def address(self,obj):
        return obj.userprofile.address
Anoop
  • 2,748
  • 4
  • 18
  • 27
  • Ok, interesting: I need to proxy the properties then? Is it not possible to specify UserProfile properties directly in the `UserAdmin.list_display`? – blueFast Feb 08 '16 at 07:57
0

You can register your extended model 'UserProfile' to the admin site. In that model, you can show your fields from OneToOneField User model.

Please check this out: One to One Field Django Admin

Community
  • 1
  • 1
Cagatay Barin
  • 3,428
  • 2
  • 24
  • 43
  • I do not want to edit, but to display the values from the related model, in the same table as the user details are displayed: the row will show both the user fields and the userprofile fields (since they are one-to-one related) – blueFast Feb 07 '16 at 16:31