Claudiu
Claudiu

Reputation: 229321

django: handler for inline admin save

When a user clicks the 'save' button on a model page of my django site, I want to do something with all the models that are to be updated, all at once. If I override save_model, it is called once per each object, but I want one function to be called with all objects to-be-updated. I overrode save_formset but it didn't work:

class ShadingAdmin(admin.ModelAdmin):
    list_display = ('foo', 'bar', 'baz')
    list_editable = ('bar', 'baz')
    list_display_links = ('foo',)
    def save_formset(self, request, form, formset, change):
        print "FOO"

admin.site.register(Shading, ShadingAdmin)

"FOO" is never printed.

I'm using Django 1.2.

Upvotes: 0

Views: 1543

Answers (1)

Laur Ivan
Laur Ivan

Reputation: 4177

formset.save() returns a list of all objects from the formset. You can call it with commit=False and the changes are only validated, not saved in the DB.

save_formset() is only called by admin (you can do a grep in django's source).

Upvotes: 1

Related Questions