[Fixed]-Why save_model method doesn't work in admin.StackedInline?

31👍

The saving isn’t done in the InlineAdmin’s save_form, you have to look at save_formsets in the ModelAdmin to which the inlines belong:

 class MyAdmin(admin.ModelAdmin):
    inlines = [MyInlineAdmin,.....]

    def save_formset(self, request, form, formset, change):
        formset.save()
        if not change:
            for f in formset.forms:
                obj = f.instance 
                obj.user = request.user
                obj.save()

Leave a comment