python - Displaying a UserProfile field in Django Admin outside listing -
i have phone
field in userprofile
. how can have displayed in django admin › auth › users
listing outside (list display) - not inside of record?
i have:
class useradmin(useradmin): list_display = ('email', 'first_name', 'last_name', 'userprofile__phone') inlines = (userprofileinline,) # re-register useradmin admin.site.unregister(user) admin.site.register(user, useradmin)
userprofile__phone not recognized.
one way be
class useradmin(useradmin): list_display = ('email', 'first_name', 'last_name', 'phone') inlines = (userprofileinline,) def phone(self, obj): try: phone = obj.userprofile.phone #or change how access userprofile object - assuming user, profile relationship onetoone return phone except: return "" phone.short_description = 'phone' # re-register useradmin admin.site.unregister(user) admin.site.register(user, useradmin)
more details on list_display
here
Comments
Post a Comment