Django admin - how to override new line in inline form set

I set up my inline model using the Media class. I want to configure inline field sets to achieve two things:

  • add a button to each line
  • run from javascript code when you click "add new line"

I tried overriding tabular.html and no matter where I place the overriden template, it does not make any difference.

From playing with change_form.html, I can say that I need to override inline_admin_formset.opts.template, but I don’t know how to do it. Any ideas?

enter image description here

+4
source share
1 answer

I get it.

  • C:\python27\Lib\-\\\\\\edit_inline\tabular.html ,
  • :

class PurchaseInlineAdmin(admin.TabularInline):
    model = Purchase
    extra = 0
    template = "admin/my_app/shoppingcart/tabular.html"
  1. tabular.html. :
<script type="text/javascript">
function beep(){
  alert('beep');
}

(function($) {
  $("#{{ inline_admin_formset.formset.prefix }}-group .tabular.inline-related tbody tr").tabularFormset({
    prefix: "{{ inline_admin_formset.formset.prefix }}",
    adminStaticPrefix: '{% static "admin/" %}',
    addText: "{% blocktrans with inline_admin_formset.opts.verbose_name|capfirst as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}",
    deleteText: "{% trans 'Remove' %}"
  });
  $(".add-row a").click(beep);
})(django.jQuery);
</script>
0

All Articles