Is it possible to make editable ForeignKey
attribute in change list?
Every user has it's UserProfile
object (OneToOneField
). I want admin to be able to modify UserProfile
expiry date from User
change list.
I can display the expiry
in change list:
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
But I can't add userprofile__expiracia
to list_editable
list. It raises:
<class 'dashboard.admin.UserCustomAdmin'>: (admin.E121) The value of 'list_editable[0]' refers to 'userprofile__expiracia', which is not an attribute of 'auth.User'.
How can I make it work?