如何防止“更改成功”?覆盖save_model方法时出现的消息 [英] How to prevent "Changed successfully" message when overriding save_model method
本文介绍了如何防止“更改成功”?覆盖save_model方法时出现的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让用户在管理员中查看记录,但不保存任何内容。所以我试图做这样的事情:
I'm trying to let users view records in the admin but not save anything. So I'm trying to do something like this:
def save_model(self, request, obj, form, change):
"""Override save method so no one can save"""
messages.error(request, "No Changes are permitted from this screen."
" To edit projects visit the 'Projects' table, and make sure you are"
" in the group 'Visitor_Program_Managers'.")
这有效,但是我在下一个屏幕上收到两条消息:
This works however I get two messages on the next screen:
我的消息首先出现在
上方,然后出现 ...已成功更改。
My message above first And then a "The ... was changed successfully."
如何阻止第二条消息?
推荐答案
您可以隐藏某些消息并显示其他消息。对于您的情况,您有兴趣不显示成功消息。您可以执行以下操作:
You can hide certain messages and show others. In your case, you are interested in not displaying the the success message. You can do the following:
def save_model(self, request, obj, form, change):
messages.set_level(request, messages.ERROR)
messages.error(request, 'No changes are permitted ..')
这篇关于如何防止“更改成功”?覆盖save_model方法时出现的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文