how can i achieve a behaviour like in the admin backend where i can add
a related object through a popup window and have it selectable after i
saved the related form?
for example:
im copleting the form book and i have to select the author but it doesnt
exist yet... so i click on the + (add) button and a popup window appears
where i create the editor object, and i can select it in the book form
right after i saved and closed this popup window.
can somebody point me to the code?
thank you in advance...
On Nov 30 2009, 5:40 am, andreas schmid <a.schmi...@gmail.com> wrote:
> Emily Rodgers wrote:
>
> > On Oct 13, 1:20 pm, andreas schmid <a.schmi...@gmail.com> wrote:
>
> >> thank you very much for pointing me to the right path!!
> >> ill try to understand the behaviour and report about my progress...
>
> >> Andrew Ingram wrote:
>
> >>> I'm assuming you are doing this somewhere other than the admin, or in
> >>> custom views, so I'll explain how the admin stuff works.
>
> >>> Basically, when you create thepopupwindowyou give it a name which
> >>> can be used the uniquely identify the field that is using thepopup
> >>> (some variant on the field id would be ideal). Your main page (not the
> >>>popup) should also have a javascript function to be called after the
> >>> new author is saved (in the case of django admin, this function is
> >>> called dismissAddAnotherPopup and is in RelatedObjectLookup.js).
>
> >>> Now the clever part (which I had to hunt around for when I needed this
> >>> functionality, you can find it around line 608 in
> >>> django.contrib.admin.options.py), is that when you successfully save
> >>> the new author, you return an HttpResponse that consists of nothing
> >>> but a script tag that executes
> >>> owner.yourFunctionName(window_name,new_object_id (in the case of the
> >>> django admin this would be owner.dismissAddAnotherPopup), window_name
> >>> is the unique identifier you passed in originally.
>
> >>> This causes the browser to execute the function in the ownerwindow
> >>> (the one that created thepopup) with the parameters you specified -
> >>> which includes the ID of the new object. Django's code also provides
> >>> the representation string of the object so it can be added to the
> >>> select box.
>
> >>> Then you just make your JS function close thepopupwith window_name.close().
>
> >>> I may not have explained it that well, but the key parts are in
> >>> RelatedObjectLookup.js and options.py (near line 608).
>
> >>> I hope this helps.
>
> >>> - Andrew Ingram
>
> >>> 2009/10/13 nabucosound <hecto...@gmail.com>:
>
> >>>> This is the default behaviour in Django Admin, dude...
>
> >>>> On Oct 13, 9:43 am, andreas schmid <a.schmi...@gmail.com> wrote:
>
> >>>>> hi,
>
> >>>>> how can i achieve a behaviour like in the admin backend where i can add
> >>>>> a related object through apopupwindowand have it selectable after i
> >>>>> saved the related form?
>
> >>>>> for example:
> >>>>> im copleting the form book and i have to select the author but it doesnt
> >>>>> exist yet... so i click on the + (add) button and apopupwindowappears
> >>>>> where i create the editor object, and i can select it in the book form
> >>>>> right after i saved and closed thispopupwindow.
>
> >>>>> can somebody point me to the code?
>
> >>>>> thank you in advance...
>
> > You might find this helpful:http://www.hoboes.com/Mimsy/hacks/replicating-djangos-admin/
>
> > Em
>
> the tutorial is nice but i cant get it really working. the problem is
> that thepopupopens but i get a:
> any suggestions?- Hide quoted text -
>
> - Show quoted text -
follow the steps on the turorial here
http://www.hoboes.com/Mimsy/hacks/replicating-djangos-admin/
sometimes its not so clear where to put the code... if you have questions ill try to help you.
ill make a "more complete" tutorial on my blog soon.
Can you please help me.
Thank you
Bhaskar
> >> - Show quoted text -- Hide quoted text -