1👍
✅
The easiest way:
def approve(self):
return self.get_queryset().update(approved=True)
NOTE: this solution has problem. post_save
and pre_save
signals will not be called.
If you need this signals, you must iterate items like you do in your example.
def approve(self):
qs = self.get_queryset()
for c in qs: # hit database!
c.approved = True
c.approved_on = #now
c.save()
return qs
Source:stackexchange.com