开发者

Django | Models where clause

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜