Add Booking.duck_booking_time() method

This commit is contained in:
Gergely Polonkai 2014-12-23 09:25:44 +01:00 committed by Gergely Polonkai
parent 6b548c80c4
commit e12019723d
2 changed files with 8 additions and 0 deletions

View File

@ -107,3 +107,7 @@ class Booking(models.Model):
@staticmethod
def total_booking_time():
return Booking.objects.filter(start_ts__isnull = False, end_ts__isnull = False).extra(select = {'amount': 'sum(strftime(%s, end_ts) - strftime(%s, start_ts))'}, select_params = ('%s', '%s'))[0].amount
@staticmethod
def duck_booking_time(duck):
return Booking.objects.filter(start_ts__isnull = False, end_ts__isnull = False, duck = duck).extra(select = {'amount': 'sum(strftime(%s, end_ts) - strftime(%s, start_ts))'}, select_params = ('%s', '%s'))[0].amount

View File

@ -184,3 +184,7 @@ class BookingTimeTest(TestCase):
def test_total_booking_time(self):
self.assertEqual(Booking.total_booking_time(), 259200)
def test_duck_booking_time(self):
self.assertEqual(Booking.duck_booking_time(self.duck1), 86400)
self.assertEqual(Booking.duck_booking_time(self.duck2), 172800)