[Django]-Django: Override get_Form inlines

5👍

admin.TabularAdmin does not have a get_form method.
The get_form function you defined is never being called.

You might want to look into get_formset method.

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.InlineModelAdmin.get_formset

👤Zahid

5👍

Inspired from the docs, I have implemented the following solution:

class Invoice(admin.ModelAdmin)
    form = InvoiceForm
    inlines =   [InvoiceDetail,]

def get_formsets_with_inlines(self, request, obj=None):
    for inline in self.get_inline_instances(request, obj):
        inline.form.current_user = request.user
        yield inline.get_formset(request, obj), inline

Leave a comment