简体   繁体   中英

django inlineformset_factory, view changed fields on save

I am creating some custom validation, that on save checks if certain fields values have changed.

On POST , is there a way in the view that I can check what fields have changed for that formset?

I am currently looping through the formset and am able to view individual field values, so I could compare them to a query. It just seems to be a bit more than necessary considering the formset doesn't go through the save process if nothing has changed.

Any help is appreciated.

Add a method to your formset:

def has_changed()
    return all([form.has_changed() for form in self.forms])

Similarly, the form also documents the changed_fields, which you can concatenate in your formset.

I don't think formset.save() blindly overwrites all entries into the db. It checks the changed forms, which I think is available in formset.changed_forms and it updates only those rows in the db.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM