我试图覆盖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
由于