[Answer]-Django: prevent certain fields from being saved in UpdateView

0👍

The problem I'm running into is, the old email gets over-written by the new one before it has been verified.

This doesn’t answer the question of how to prevent fields from being saved using an UpdateView but it solves the stated problem above.

# views.py snippet
# because we are using the same 'email' variable to add new email addresses
# 'self.object.email' will be saved with the new provided value
# to prevent this from happening, manually set the 'email' variable to the value
# retrieved from the DB
except Account.DoesNotExist:
            verifystring = get_random_string()
            self.object.email = old_email
            self.object.new_email = new_email

1👍

This doesn’t have much to do with the class-based fields, but with the problem of not losing an address that is known to be working.

I suggest you to add a field to your Account model, called new_email or unverified_email or something; when the account is changed, the actual email field is left untouched, and the new address is stored into that new field, and the verification email is sent to it.

Only when the verification process is complete, the new address is stored into the email field, overriding the old address. It would also be prudent to warn the user in the update form that their old address will be used until they verify the new address.

Leave a comment