关闭django管理员在保存时添加相关对象弹出窗口

关闭django管理员在保存时添加相关对象弹出窗口

本文介绍了关闭django管理员在保存时添加相关对象弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在django管理员中,当用户成功保存(在我的清理方法之后)在弹出窗口中编辑的新的或更改的相关对象时,我希望弹出窗口关闭,而不是进入不同的视图。 p>

我相信可以使用response_change或response_add来查看其他视图,但是有没有办法让窗口关闭?

解决方案

查看原始的 response_change response_add 方法做:他们返回一个javascript,在父窗口中调用JS方法,关闭弹出窗口。

  return HttpResponse('''
< script type =text / javascript>
opener.dismissAddAnotherPopup(window);
< / script>'''

在父窗口中,有一个脚本具有相关方法:

  function dismissAddAnotherPopup(win){
win.close();

(原始版本传递更多参数,所以它用新对象更新父窗口,但是如果您只想关闭窗口,则不需要。)


In the django admin, when a user successfully saves (after my clean method) a new or changed related object which was edited in a popup, I'd like the popup to close instead of going to a different view.

I believe I could use response_change or response_add to get it to go to a different view, but is there a way I can get the window to close?

解决方案

Look at what the original response_change or response_add methods do: they return a piece of javascript that calls a JS method in the parent window, which closes the popup.

return HttpResponse('''
   <script type="text/javascript">
      opener.dismissAddAnotherPopup(window);
   </script>'''

and in the parent window, have a script that has the relevant method:

function dismissAddAnotherPopup(win) {
    win.close();
}

(The original version passes more parameters, so it updates the parent window with the new object, but you don't need that if you just want to close the window.)

这篇关于关闭django管理员在保存时添加相关对象弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:56