I've been looking for a simple way to send an email when a user
updates their profile.
After some digging I found form.has_changed() which appears to fit the
bill. However, it always seems to return true, so I could end up
bombarding our elderly admin lady with lots of useless emails.
I'm using a simple model form (with a sub-set of the available
fields), rendered in the default manner, no hidden fields or anything.
If I open the page, hit save, if form.has_changed(): runs.
Is there anything else that might cause has_changed to be true?
Perhaps this is why has_changed() isn't mentioned in the documentation?
I kinda hope I'm being stupid on this one, I'd rather not get into a
long comparison function!
-Alastair
Hi everyone,
I've been looking for a simple way to send an email when a user
updates their profile.
After some digging I found form.has_changed() which appears to fit the
bill. However, it always seems to return true, so I could end up
bombarding our elderly admin lady with lots of useless emails.
I'm using a simple model form (with a sub-set of the available
fields), rendered in the default manner, no hidden fields or anything.
If I open the page, hit save, if form.has_changed(): runs.
Is there anything else that might cause has_changed to be true?
Margie
Thanks for the tip, when I do that, every filled-in field is returned
as changed.
I've put the model form definition and the view up here:
http://dpaste.com/142308/
Any idea what I'm doing wrong? Perhaps something to do with loading
the form with data in the first place?
Kind regards,
-Alastair
I've put the model form definition and the view up here:
http://dpaste.com/142308/
Any idea what I'm doing wrong? Perhaps something to do with loading
the form with data in the first place?
Thanks Karen, that worked great.
I had done quite a few non-model forms, which is a more manual
process, I hadn't twigged that you save the form rather than the
model. After that, the changed form aspect works great and I can
selectively output the changed data.
Thanks for the help,
-Alastair
On Jan 12, 12:43 am, Alastair Campbell <ala...@gmail.com> wrote:
Btw, has_changed() doesn't seem to work on non-model forms, does it?
if I digress from the has_changed() problem, you mentioned you
wanted to send email after a user profile has changed. Assuming that
the profile is a model in the database, you might consider tying your
logic to the model rather than the form.
The post_save signal tied to the profile-related model might just do
the trick for you.
Cheers
Jirka