Reputation: 26227
I've been using Django for over a year, but I think I've missed out on some very fundamental thing. I have a rather large queryset (1000+ objects) and I'd like to change a single attribute for each of the objects in that queryset. Is this really the way to go? I'm sure there is something simpler?
for obj in qs:
obj.my_attr = True
obj.save()
Thanks
Upvotes: 4
Views: 4742
Reputation: 488544
You can just do the changes in bulk, although this will not fire the Model's save()
callbacks:
MyModel.objects.filter(..).update(my_attr=True)
Documentation: Updating multiple objects at once
Upvotes: 19