Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django管理-列表\可编辑-外键属性?_Python_Django_Django Admin_Django 1.10 - Fatal编程技术网

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
用于实际更新对象的方法。