spradio-server-django/savepointradio/profiles/managers.py

22 lines
626 B
Python
Raw Normal View History

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):
return self.get_queryset().filter(played_at__isnull=True)
2018-01-18 17:45:00 +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')