2013-07-23 72 views
0

我在我的UserProfile中有phone字段。我如何從外部列表中顯示Django Admin › Auth › Users列表(列表顯示) - 而不是記錄內部?在Django Admin外部列表中顯示UserProfile字段

我現在有:

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無法識別。

+0

你怎麼從外面意思

class UserAdmin(UserAdmin): list_display = ('email', 'first_name', 'last_name', 'phone') inlines = (UserProfileInline,) def phone(self, obj): try: phone = obj.userprofile.phone #Or change this to how you would access the userprofile object - This was assuming that the User, Profile relationship is OneToOne return phone except: return "" phone.short_description = 'Phone' # Re-register UserAdmin admin.site.unregister(User) admin.site.register(User, UserAdmin) 

更多細節?你的意思是在列表中顯示? – karthikr

+0

@karthikr是的.. –

回答

相關問題