开发者

Django | Models where clause

开发者 https://www.devze.com 2022-12-30 13:53 出处:网络
How to construct a where clause 开发者_开发知识库using Django models: insert in to tablename where email=emailaddress

How to construct a where clause 开发者_开发知识库using Django models:

insert in to tablename where email=emailaddress

Thanks.


I think you are rather looking for a possibility to UPDATE an existing object.

obj=MyModel.objects.get(email=emailaddress)
obj.name = 'xxxx'
obj.save()


In case the email address is not unique, which is strange but let's suppose that, you should use the filter method and loop on result

users = MyObject.objects.filter(email=emailaddress)
for u in users:
    # your change here
    u.is_superuser = True
    u.save()
0

精彩评论

暂无评论...
验证码 换一张
取 消