是否可以在更改列表中创建可编辑的ForeignKey
属性?
每个用户都有UserProfile
个对象(OneToOneField
)。我希望管理员能够从UserProfile
更改列表修改User
到期日期。
我可以在更改列表中显示expiry
:
class UserCustomAdmin(UserAdmin):
list_display = ['id', 'username','email', 'last_login','userprofile__expiracia']
# list_editable = ['userprofile__expiracia']
exclude = ['groups','user_permissions']
inlines = [UserProfileInline]
fieldsets = (
(None, {'fields': ('username', 'password')}),
(_('Personal info'), {'fields': ('first_name', 'last_name', 'email')}),
(_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser',
)}),
(_('Important dates'), {'fields': ('last_login', 'date_joined')}),
)
def userprofile__expiracia(self,obj):
return obj.userprofile.expiracia
但我无法将userprofile__expiracia
添加到list_editable
列表中。它提出了:
<class 'dashboard.admin.UserCustomAdmin'>: (admin.E121) The value of 'list_editable[0]' refers to 'userprofile__expiracia', which is not an attribute of 'auth.User'.
我怎样才能让它发挥作用?