我正在尝试覆盖 django UserAdmin save_model 方法。在某些情况下,我想忽略保存数据,但它总是保存数据。我是不是错过了什么。这是我的代码
class MyUserAdmin(UserAdmin):
def save_model(self, request, obj, form, change):
attrs = request.POST
role=attrs.getlist('userProfile_user-0-role',None)
if change:
if int(role[0]) == 1:
super(MyUserAdmin, self).save_model(request, obj, form, change)
else:
messages.error(request, "Subscriptions cannot be changed.")
# In this case I did not want save data
谢谢