1👍
✅
You can implement this by subclassing the QuerySet
. For example with:
from django.db.models import QuerySet
class MyModelQuerySet(QuerySet):
def close(self):
return self.update(status='closed', open_time=None, opener=None)
def close_stuff(self, *args, **kwargs):
return self.get_stuff_to_close_query_set(*args, **kwargs).close()
def get_stuff_to_close_query_set(self, time):
self.filter(…)
Then we can plug this into the MyModel
:
class MyModel(models.Model):
# …
objects = MyModelQuerySet.as_manager()
Source:stackexchange.com