diff --git a/booking/models.py b/booking/models.py index 8a770c4..4f6aa6d 100644 --- a/booking/models.py +++ b/booking/models.py @@ -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 diff --git a/booking/tests.py b/booking/tests.py index dda1e70..968c351 100644 --- a/booking/tests.py +++ b/booking/tests.py @@ -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)