title: Override save_model and close window
body: <p>I am writing code to open a new window inside the django admin to add a model instance and to close on save. This is very similar to the behaviour of ForeignKey field add (green plus sign) does, but without selecting the newly created model instance (because its not a foreign key field).</p>
  
  <p>The code I add to make the pop-up link is:</p>
  
  <pre><code>link = '&lt;a id="add_id_event" class="add-another" onclick="return showAddAnotherPopup(this);" href="%s?date=%s"&gt;add&lt;/a&gt;' % ( addurl,currentdate)
  </code></pre>
  
  <p>where my model is called Event. I correctly add RelatedObjectLookups.js</p>
  
  <p>When I try to save this model, django applies the same code it would use on a ForeignKey field and tries to activate a SelectBox which I don't have. This causes the javascript to fail before it gets to the window.close()</p>
  
  <p>I've tried overriding the save_model function with</p>
  
  <pre><code>def save_model(self, request, obj, form, change):
      if request.GET.get('_popup') == '1':
          obj.save()
          return HttpResponse('&lt;script type="text/javascript"&gt;window.close()&lt;/script&gt;')
  </code></pre>
  
  <p>This code is used but the HttpResponse call is ignored and django renders the default. e.g.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;opener.dismissAddAnotherPopup(window, "14382", "TMC 2012\u002D02\u002D02 10:00:00 DDT2010B\u002D028");&lt;/script&gt;
  </code></pre>
  
  <p>which fails because there is no destination SelectBox object.</p>
  
  <p>Thanks for your help.</p>