I would do something like this:
(我会做这样的事情:)
from allauth.account.models import EmailAddress
with transaction.atomic():
# password with old one
user.password = user_old_password
user.save(update_fields=['password'])
# validate user
EmailAddress.objects.get_or_create(
user=user,
email=user.email,
verified=True
)
Atomic transaction here if you plan to do it in a migration file.
(如果您计划在迁移文件中进行原子事务,请在此处进行。)
See migration files in django doc (查看Django文档中的迁移文件)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…