Fix booking models

Indentation, line breaks, etc.
This commit is contained in:
Gergely Polonkai 2015-10-19 14:58:32 +02:00
parent cdce3803a5
commit 0678db84df

View File

@ -59,11 +59,11 @@ class Duck(models.Model):
comps = models.ManyToManyField(Competence, through='DuckCompetence') comps = models.ManyToManyField(Competence, through='DuckCompetence')
donated_by = models.ForeignKey(User) donated_by = models.ForeignKey(User)
donated_at = models.DateTimeField(default=timezone.now) donated_at = models.DateTimeField(default=timezone.now)
adopted_by = models.ForeignKey(User, related_name = 'adopted_ducks', null = True) adopted_by = models.ForeignKey(User, related_name='adopted_ducks', null=True, blank=True)
adopted_at = models.DateTimeField(null = True) adopted_at = models.DateTimeField(null=True, blank=True)
bookings = models.ManyToManyField(User, through='Booking', related_name='+') bookings = models.ManyToManyField(User, through='Booking', related_name='+')
on_holiday_since = models.DateTimeField(null = True) on_holiday_since = models.DateTimeField(null=True, blank=True)
on_holiday_until = models.DateTimeField(null = True) on_holiday_until = models.DateTimeField(null=True, blank=True)
def __str__(self): def __str__(self):
if self.name == None or self.name == '': if self.name == None or self.name == '':
@ -144,8 +144,20 @@ class Booking(models.Model):
@classmethod @classmethod
def total_booking_time(cls): def total_booking_time(cls):
return cls.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 return cls.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
@classmethod @classmethod
def duck_booking_time(cls, duck): def duck_booking_time(cls, duck):
return cls.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 return cls.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