Python – Django: change the value of a field for all objects in a queryset

djangodjango-querysetpython

I have a model MyModel with a boolean field active

Elsewhere, I am retrieving a queryset:

qs = MyModel.Objects.filter(....) 

how can I set active=False for all objects in this qs?

Best Answer

You can update all the records in the queryset with

qs.update(active=False)

Please refer to the official Django documentation for more info