列值以下为python manage shell
SQL命令来更新表
>>> User.objects.filter(email__icontains="gmail.com").values_list("email", flat=True)
[u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]']
>>> for ii in User.objects.filter(email__icontains="gmail.com"):
... ii.email = ii.email.replace("@gmail.com", "@custom.com")
... ii.save()
...
...
>>> User.objects.filter(email__icontains="gmail.com").values_list("email", flat=True)
[]
>>> User.objects.filter(email__icontains="@custom.com").values_list("email", flat=True)
[u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]']
>>>
我想在PostgreSQL终端(python manage dbshell
)
写SQL命令代码,我怎么能上述转换的SQL命令?
以下是我的尝试:
[Edited1]:
通过SQL命令获取目标的电子邮件ID:
dp=# SELECT email FROM auth_user where email LIKE '%@gmail.com';
email
---------------------------
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
(5 rows)
dp=#
@谢谢你,增加投票。我也添加我的答案,你可以检查我的答案吗? –