I want to override submit_line.html for a single model or a single app (either will work - the app has just one model). I see in the docs I cannot do that (https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#templates-which-may-be-overridden-per-app-or-model)
Is there some way to test for what model or app the template is being called for so I can add some conditional behaviour? Or perhaps is there some way to have a different template used in place of submit_line.html for a specific app or model?
mishbah's answer has solved my initial problem, but now I am facing another issue - when my code is done, something runs that add the row. I don't want that to happen.
Here's what I am trying to accomplish:
- User clicks add button
- Add object page is shown with my custom button
- When my button is clicked I execute an ajax call and display the results below the add div, and this page is shown until the user clicks a button.
This all works - my only issue is that a rows get added to the database - I would somehow like to prevent that from happening.
Here is my code:
On the main admin page I have just the add button:
Here is my change_form.html:
{% extends "admin/change_form.html" %}
{% block submit_buttons_bottom %}
<style type="text/css">
#id_tool_configuration {
white-space: pre-wrap;
}
</style>
<div class="submit-row">
<input 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;
var request = new XMLHttpRequest();
var params = 'toolConfigData='+encodeURIComponent(toolConfigData);
request.open('GET', '{% url 'motor.configuration.views.configure' %}?'+params);
request.setRequestHeader("Content-type", "text/plain; charset=utf-8");
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200) {
status = 'Confguration results:';
}
else {
status = 'Confguration failed';
}
$('.submit-row').after(
$('<span />')
.html('<pre> ' + status + '\n' + request.responseText + '</pre>')
.after($('<button />').text('Return').click('function () { return; }'))
);
}
};
request.send(null);
return false;
};
</script>
{% endblock %}