我想查看更改的数据,如果有任何字段更改,我想将其邮寄到管理员电子邮件。
这是我的代码:
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
. 我该如何克服这个问题?