On Tue, Apr 7, 2015 at 7:04 PM, Larry Martell <larry.mart...@gmail.com> wrote:
> On Tue, Apr 7, 2015 at 5:40 PM, Larry Martell <larry.mart...@gmail.com> wrote:
>> I have a model and I want to have this behaviour in admin:
>>
>> 1. Only the add button is shown.
>> 2. When the user clicks the add button, it brings up the standard
>> page, but with just 1 custom button shown.
>> 3. When the user clicks that custom button, I execute an ajax call and
>> display the results below the add div, and this page is shown until
>> the user clicks a button.
>>
>> I have all this coded, but I am facing the following problems:
>>
>> 1. I am not getting the response back from my ajax call. In the Chrome
>> developers tools, in the network tab for this request, in the
>> Status/Text column, it says "(cancelled)" - not sure what that means.
>> If I run the same request from my browser I do get a response. On the
>> server side I am getting 'error: (32, 'Broken pipe')' Googling that
>> revealed that it's because the browser has already moved on, so there
>> is nothing to receive the response. I've tried setting the timeout to
>> a large value, but no joy. How can I get it to wait for the response?
>
> I solved the above issue - I was not returning false from the onclick
> hander. Once i did that I started getting the response.
>
>
> But I am still trying to solve the 2 issues below.
>
>> 2. It immediately returns back to the main admin page - how can I get
>> it to stay on the add page until the users clicks a button?

I solved this issue -  I removed type="submit" from my custom button.
I then added another button they can click to return.

Now I'm left with just issue 3 - how to prevent the row from being
added to the database. Anyone know how to do that?

>> 3. After my code returns, a row is added to the database. How can I
>> prevent the row from being added?
>>
>> This is my change_form.html:
>>
>> {% extends "admin/change_form.html" %}
>>
>> {% block submit_buttons_bottom %}
>>     <div class="submit-row">
>>     <input type="submit" value="Configure" class="default"
>> name="configure"
>> onclick="configureTools(document.getElementById('id_tool_configuration').value);"
>> />
>>     </div>
>>
>> <script src="/static/scripts/jquery-1.7.js" type="text/javascript"></script>
>>
>> <script type="text/javascript">
>>     function configureTools(tcd) {
>>         var toolConfigData = tcd;
>>         $.ajax({
>>             type : 'GET',
>>             url: '{% url 'motor.configuration.views.configure' %}',
>>             data: 'toolConfigData='+toolConfigData,
>>             success: function(configOut) {
>>                 $('.submit-row').after(
>>                     $('<span />')
>>                     .html('<pre> Confguration succeded\n'+configOut+'</pre>')
>>                 );
>>             },
>>             error: function(configOut) {
>>                 $('.submit-row').after(
>>                     $('<span />')
>>                     .html('<pre> Confguration failed\n'+configOut+'</pre>')
>>                 );
>>             }
>>         });
>>     };
>> </script>
>>
>> {% endblock %}

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwCsY4zMTX%3DFQ8BawWn959eJ17mcTrD77LkTaTZVf-C7SopQg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to