Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8065315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:37:46+00:00 2026-06-05T11:37:46+00:00

I am writing code to open a new window inside the django admin to

  • 0

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

The code I add to make the pop-up link is:

link = '<a id="add_id_event" class="add-another" onclick="return showAddAnotherPopup(this);" href="%s?date=%s">add</a>' % ( addurl,currentdate)

where my model is called Event. I correctly add RelatedObjectLookups.js

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

I’ve tried overriding the save_model function with

def save_model(self, request, obj, form, change):
    if request.GET.get('_popup') == '1':
        obj.save()
        return HttpResponse('<script type="text/javascript">window.close()</script>')

This code is used but the HttpResponse call is ignored and django renders the default. e.g.

<script type="text/javascript">opener.dismissAddAnotherPopup(window, "14382", "TMC 2012\u002D02\u002D02 10:00:00 DDT2010B\u002D028");</script>

which fails because there is no destination SelectBox object.

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:37:48+00:00Added an answer on June 5, 2026 at 11:37 am

    You’ll need to override ModelAdmin.response_add. That’s where the redirect is happening.

    In my case, I needed to override the dismissAddAnotherPopup method, so I created a new one called dismissAddAnotherPopupWithUpdate to handle my fancy M2M widgets. Here’s the code i used:

    def response_add(self, request, obj, post_url_continue='../%s/'):
        """
        Overriding to force the widget to update
        """
        resp = super(ModelAdmin, self).response_add(request, obj, post_url_continue)
        if request.POST.has_key("_popup"):
            return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopupWithUpdate(window, "%s", "%s");</script>' % \
                # escape() calls force_unicode.
                (escape(obj._get_pk_val()), escape(obj)))
        return resp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to force links to open in a new window/tab using javascript
I'm opening new page using JS and writing into it the HTML code, however
Scenario: I'm creating a new window (new tab) and writing html markup to it
I want to open a new terminal window, which will run a certain command
With this code for a very basic logger: lock (string.Concat(LogWritter_, this.FileName)) { using (var
I know that many of us are writing code to open an InfoWindow when
While writing code in a file that would comprise of PHP, HTML, CSS &
While writing code, it is pretty common to request a page with an appended
When writing code in an Eclipse project, I'm usually quite messy and undisciplined in
I am currently writing code in C++ to find all possible permutations of 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.