I have a Comment model that needs the admin approval. I am providing a view for the admin to do that.
However, I am using an expensive way to update the approval status.
comments = # a list that contain Comment objects
for c in comments:
c.approved = True
c.approved_on = #now
c.save()
As you can see I am looping over all the objects in the list and every time I am hitting the database.
I am looking for a way that makes me do something similar to this in SQL
UPDATE comments SET approved = 1 WHERE id IN(...........)
This will do the same thing in one SQL query.
Is there any way to do this in Django?
like this with using an approve method in the manager?
Comment.objects.filter(pk__in=[1,2,3]).approve().save()