Update Multiple Objects using SQL way in Django -
I have a However, I am using an expensive method to update the approval status. As you can see, I am looping all the objects in the list and every time I am killing the database. I am looking for a way in which I have to do something like SQL This will do the same thing in a single SQL query. Is there any way to do this in Django? In this way, with the use of an approval method in the manager? Easiest way: Note : The problem with this solution is If you need this signal, you will have to recreate items such as in your examples. comment model that requires admin approval. I am providing a view to admin to do this
comments = # Comment with a comment object for C: c.approved = true C.approved_on = #now c.save ()
as UPDATE comments SET Approved = 1 WHERE id (....... ....)
comment.blogs.filter (pk__in = [1,2,3]). Approved (). ()
def Approval (self): back to self .get_queryset (). Update (Approved = true)
post_save and
pre_save signals Will not be called.
DIFF (self): qs = self.get_queryset () for qs in C: #Hit database! C.approved = true c.approved_on = #now c.save () return qs
Comments
Post a Comment