views:

301

answers:

1

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?

+1  A: 

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.)

Daniel Roseman