hi, yes it works perfectly :)

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. 


Bhaskar Gara wrote:
> Hi Andrew,  Do you have any luck on this. I need same functionality.
>
> 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:
>>
>>     TypeError at /popadd/topics/
>>
>>     'str' object is not callable
>>
>>     Request Method:     GET
>>     Request URL:    http://127.0.0.1:8000/de/popadd/topics/?_popup=1
>>     Exception Type:     TypeError
>>     Exception Value:    
>>
>>     'str' object is not callable
>>
>>     Exception Location:    
>>     /home/pepe/DEV/FSlabs/parts/django/django/core/handlers/base.py in
>>     get_response, line 92
>>
>> my views.projects ProjectForm:
>>
>>     class ProjectForm(ModelForm):
>>         topics       = ModelMultipleChoiceField(Topic.objects,
>>     required=False, widget=MultipleSelectWithPop)
>>         technologies = ModelMultipleChoiceField(Technology.objects,
>>     required=False, widget=MultipleSelectWithPop)
>>         class Meta:
>>             model = Project
>>             exclude = ['author']
>>
>> my views.handlePopAdd.py :
>>
>>     from django.utils.html import escape
>>     from django.contrib.auth.decorators import login_required
>>
>>     from myapp.views.technologies import TechnologyForm
>>     from myapp.views.topics import TopicForm
>>
>>     def handlePopAdd(request, addForm, field):
>>         if request.method == "POST":
>>             form = addForm(request.POST)
>>             if form.is_valid():
>>                 try:
>>                     newObject = form.save()
>>                 except forms.ValidationError, error:
>>                     newObject = None
>>                 if newObject:
>>                     return HttpResponse('<script
>>     type="text/javascript">opener.dismissAddAnotherPopup(window, "%s",
>>     "%s");</script>' % \
>>                         (escape(newObject._get_pk_val()),
>>     escape(newObject)))
>>
>>         else:
>>             form = addForm()
>>
>>         pageContext = {'form': form, 'field': field}
>>         return render_to_response("add/popadd.html", pageContext)
>>
>>     @login_required
>>     def newTopic(request):
>>         return handlePopAdd(request, TopicForm, 'topics')
>>
>>     @login_required
>>     def newTechnology(request):
>>         return handlePopAdd(request, TechnologyForm, 'technologies')
>>
>> any suggestions?- Hide quoted text -
>>
>> - Show quoted text -
>>     
>
>   

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to