Python Django管理-列表\可编辑-外键属性?
是否可以在变更列表中设置可编辑的Python Django管理-列表\可编辑-外键属性?,python,django,django-admin,django-1.10,Python,Django,Django Admin,Django 1.10,是否可以在变更列表中设置可编辑的ForeignKey属性 每个用户都有它的UserProfile对象(OneToOneField)。我希望管理员能够从User更改列表中修改UserProfile到期日期 我可以在更改列表中显示到期: class UserCustomAdmin(UserAdmin): list_display = ['id', 'username','email', 'last_login','userprofile__expiracia'] # list_edi
ForeignKey
属性
每个用户都有它的UserProfile
对象(OneToOneField
)。我希望管理员能够从User
更改列表中修改UserProfile
到期日期
我可以在更改列表中显示到期
:
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\uuuuuuexpiracia
添加到list\u 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'.
:(admin.E121)“列表可编辑[0]”的值指的是“userprofile\uu expiracia”,它不是“auth.User”的属性。
如何使其工作?您可能会覆盖
list\u editable
用于实际更新对象的方法。