変更されたデータを確認したいのですが、フィールドが変更された場合は、それを管理者の電子メールに送信したいと考えています。
これが私のコードです:
def send_change_email(changed_data, cleaned_data, merchant):
changed_stuff = {}
for key in changed_data:
changed_stuff[key] = cleaned_data[key]
rendered = render_to_string('model_change.txt', {'changed_stuff':changed_stuff, 'merchant':merchant })
send_mail('Model Change!', rendered, 'no-reply@mysite.com', ['hi@test.com'])
class FooForm(forms.Form):
field_1 = forms.CharField()
field_2 = forms.CharField()
def clean(self): # Here I test if any field is changed, if so, mail to them
if self.is_valid() and self.changed_data:
send_change_email(self.changed_data, self.cleaned_data, None)
return self.cleaned_data
問題は、私がしようとすると、常にフィールドの完全なリストを取得することself.changed_data
です。どうすればこの問題を克服できますか?