Added traveller count + hyperlinks to bus and shuttle view

This commit is contained in:
John Mullins
2023-08-28 15:27:24 +10:00
parent f9981aadf0
commit 2f1ae0586b
2 changed files with 41 additions and 4 deletions
+14
View File
@@ -84,6 +84,13 @@ class Bus(models.Model):
def __str__(self):
return f"{self.route_name}"
def traveller_count(self):
count = 0
for traveller in Traveller.objects.filter(bus_stops__bus=self):
if traveller.is_active():
count += 1
return count
class Shuttle(models.Model):
bus = models.ForeignKey(Bus, on_delete=models.CASCADE)
@@ -95,6 +102,13 @@ class Shuttle(models.Model):
def __str__(self):
return f"{self.school.shortName} <-> {self.bus.route_name}"
def traveller_count(self):
count = 0
for traveller in Traveller.objects.filter(shuttle=self):
if traveller.is_active():
count += 1
return count
class Driver(models.Model):
bus = models.ForeignKey(Bus, on_delete=models.CASCADE)