开发者

Detect which fields change in a Django ModelForm

开发者 https://www.devze.com 2023-04-04 11:19 出处:网络
I have an app where user submitted data needs to go through a verification process before it shows up on the site. At the moment this means they cannot edit the item without removing it from the site

I have an app where user submitted data needs to go through a verification process before it shows up on the site. At the moment this means they cannot edit the item without removing it from the site (so our admins can check it's okay).

I'd like to write another model where I can store revisions. Basically three fields where I store the date submitted, a boolean saying if the user is ready for that revision to be considered and a third where I store all the changes (as a pickled/JSON dict).

The problem I have at the moment is I don't want to bombard the admins with a complete listing each time. I only want them to see the changed fields. This means I need a way of generating a list of which fields have changed when the user submits the edit ModelForm so I only save this data in the revision.

There are probably several ways of doing this but my post-pub-quiz brain is slightly numb and can't think of the best way. How would you开发者_StackOverflow do it?

In terms of where this would go, I'd probably write it as an abstract ModelForm-inheriting class that other forms use. I'd override save() to stop it writing the data directly back to database (I'd want to redirect it through this fancy new revisions model).

Come to think of it, is there an app that already does this generically?

0

精彩评论

暂无评论...
验证码 换一张
取 消