Add Booking.duck_booking_time() method
This commit is contained in:
parent
6b548c80c4
commit
e12019723d
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user