36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
from django.db import models
|
|
|
|
|
|
class RequestManager(models.Manager):
|
|
def get_queryset(self):
|
|
return super().get_queryset()
|
|
|
|
def unplayed(self):
|
|
return self.get_queryset().filter(played_at__isnull=True)
|
|
|
|
def played(self):
|
|
return self.get_queryset().filter(models.Q(queued_at__isnull=False) |
|
|
models.Q(played_at__isnull=False))
|
|
|
|
def not_queued(self):
|
|
return self.get_queryset().filter(queued_at__isnull=True)
|
|
|
|
def queued(self):
|
|
return self.get_queryset().filter(queued_at__isnull=False)
|
|
|
|
def new_requests(self):
|
|
return self.get_queryset().filter(models.Q(queued_at__isnull=True) &
|
|
models.Q(played_at__isnull=True))
|
|
|
|
def get_played_requests(self, limit=None):
|
|
if limit:
|
|
return self.played()[0:limit]
|
|
return self.played()
|
|
|
|
def get_queued_requests(self, limit=None):
|
|
if limit:
|
|
return self.queued()[0:limit]
|
|
return self.queued()
|
|
|
|
def next_request(self):
|
|
return self.new_requests().earliest('created_date')
|