From e12019723dae9f488c2553823665e79db56ae89a Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 23 Dec 2014 09:25:44 +0100 Subject: [PATCH] Add Booking.duck_booking_time() method --- booking/models.py | 4 ++++ booking/tests.py | 4 ++++ 2 files changed, 8 insertions(+) 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)