I managed to get this working, sort of. I learned that I need to include 
jquery.init.js to my parent form. otherwise It wont open in a new window. 
Now the only issue I am encountering is after I submit my child form, the 
window goes white, but does not close. I think the code that gets called 
when I submit the form is this 
return HttpResponse('<script 
type="text/javascript">opener.dismissAddRelatedObjectPopup(window, "%s", 
"%s");</script>' % \
(escape(newObject._get_pk_val()), escape(newObject)))
I cant figure out if its being called at all or if its being called on the 
child or if its being called on the parent and thats why its not closing. 
"window" is being staticaly typed so its not in the view code other than 
that one spot. 

Here is the Django code for the dismiss function (this was pulled directly 
from  
https://github.com/django/django/blob/master/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
function dismissAddRelatedObjectPopup(win, newId, newRepr) {
       var name = windowname_to_id(win.name);
       var elem = document.getElementById(name);
       if (elem) {
           var elemName = elem.nodeName.toUpperCase();
           if (elemName === 'SELECT') {
               elem.options[elem.options.length] = new Option(newRepr, newId
, true, true);
           } else if (elemName === 'INPUT') {
               if (elem.className.indexOf('vManyToManyRawIdAdminField') !== 
-1 && elem.value) {
                   elem.value += ',' + newId;
               } else {
                   elem.value = newId;
               }
           }
           // Trigger a change event to update related links if required.
           $(elem).trigger('change');
       } else {
           var toId = name + "_to";
           var o = new Option(newRepr, newId);
           SelectBox.add_to_cache(toId, o);
           SelectBox.redisplay(toId);
       }
       win.close();
   }

I can see that after I submit my new object gets selected in the dropdown 
inside the parent form, but the popup window from the child form does not 
close. Any ideas how to get the child form to close, the dismiss function 
should be doing that correct?


On Wednesday, April 20, 2016 at 5:06:22 PM UTC-4, Giuseppe wrote:
>
> I am trying to get a pop up that will let me create a new object to 
> associate to a many to many relationship on a form/model. In the same way 
> that it works in django-admin.
>
> I have been followed the instructions from here 
> <http://www.hoboes.com/Mimsy/hacks/replicating-djangos-admin/>, and its 
> not working for me. 
>
> whenever I click the plus button it opens the related object creating form 
> in the same tab instead of a new pop up. When I try to submit the new 
> object I get a cert error and I included the cert tag in the template.
>
> Let me know what code you want to see and I can post it. Also if you know 
> of a different resource, or library or way of doing this that would be 
> amazing.
>
> By the way I think the link provided was for django 1.1 and im using 
> django 1.9.1
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dbba1952-d5b3-4fc1-a68f-cc48fc4a508c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to