2018-01-18 17:45:00 +00:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
class RequestManager(models.Manager):
|
|
|
|
def get_queryset(self):
|
|
|
|
return super().get_queryset()
|
|
|
|
|
|
|
|
def unplayed(self):
|
2018-09-24 17:03:42 +00:00
|
|
|
return self.get_queryset().filter(played_at__isnull=True)
|
2018-01-18 17:45:00 +00:00
|
|
|
|
2018-03-30 02:58:06 +00:00
|
|
|
def played(self):
|
|
|
|
return self.get_queryset().filter(models.Q(queued_at__isnull=False) |
|
|
|
|
models.Q(played_at__isnull=False))
|
|
|
|
|
|
|
|
def get_played_requests(self, limit=None):
|
|
|
|
if limit:
|
|
|
|
return self.played()[0:limit]
|
|
|
|
return self.played()
|
|
|
|
|
2018-01-18 17:45:00 +00:00
|
|
|
def next_request(self):
|
|
|
|
return self.unplayed().earliest('created_date')
|