Django | Models where the article

How to create a where clause using Django models:

insert in to tablename where email=emailaddress

Thank.

+3
source share
2 answers

I think you are rather looking for an UPDATE option for an existing object.

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

In case the email address is not unique, which is strange, but suppose you have to use the filter method and the loop for the result

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

Source: https://habr.com/ru/post/1746070/


All Articles