2016-05-06 20:33:59 +00:00
|
|
|
from psycopg2.extras import DateTimeTZRange
|
|
|
|
|
|
|
|
from django.db.models import QuerySet
|
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
|
2016-05-10 20:20:01 +00:00
|
|
|
class ProductQuerySet(QuerySet):
|
2016-05-06 20:33:59 +00:00
|
|
|
|
|
|
|
def available(self):
|
|
|
|
now = timezone.now()
|
|
|
|
return self.filter(
|
|
|
|
available_in__contains=DateTimeTZRange(now, None)
|
|
|
|
)
|
2016-06-01 09:10:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OrderQuerySet(QuerySet):
|
|
|
|
|
|
|
|
def not_cancelled(self):
|
|
|
|
return self.filter(cancelled=False)
|
|
|
|
|
|
|
|
def open(self):
|
|
|
|
return self.filter(open__isnull=True)
|
|
|
|
|
|
|
|
def paid(self):
|
|
|
|
return self.filter(paid=True)
|
|
|
|
|
|
|
|
def unpaid(self):
|
|
|
|
return self.filter(paid=False)
|
|
|
|
|
|
|
|
def cancelled(self):
|
|
|
|
return self.filter(cancelled=True)
|