diff --git a/vehicles/models.py b/vehicles/models.py index 6b6383d..a963c84 100644 --- a/vehicles/models.py +++ b/vehicles/models.py @@ -26,11 +26,30 @@ class Vehicles(models.Model): nBases = models.CharField('Basé à ', max_length=1, choices=BASES_CHOICES, default=1) nStatus = models.CharField('Statut', max_length=1, choices=STATUS_CHOICES, default=1) - a_infos = [] + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.a_infos = None - def get_all_infos(self): - infos = Vehicles_infos.filter(Vehicles__id=self.id) - print(infos) + + def get_all_infos(self,nType): + if self.a_infos is not None: + return self.a_infos[f"{nType}"] + + self.a_infos = {"1": [], "2": [], "3": []} + infos = Vehicles_infos.objects.filter(Vehicle__id=self.id,bEnabled=1) + for info in infos: + self.a_infos[f"{info.nType}"].append(info) + print(self.a_infos[f"{nType}"]) + return self.a_infos[f"{nType}"] + + def get_all_infos_tech(self): + return self.get_all_infos(1) + + def get_all_infos_mat(self): + return self.get_all_infos(2) + + def get_all_infos_perempt(self): + return self.get_all_infos(3) @@ -55,6 +74,12 @@ class Vehicles_infos(models.Model): dtUpdated = models.DateTimeField('date updated', auto_now=True) dtCreated = models.DateTimeField('date published', auto_now_add=True) + def get_Start_formated(self): + return self.dtStart.strftime("%d.%m") + def get_Author_formated(self): + return self.Author.username.replace("@clerc.ch",'') + + def __str__(self): return self.sDesc diff --git a/vehicles/templates/vhc/vhc.html b/vehicles/templates/vhc/vhc.html index 5fdf2c7..1672b5c 100644 --- a/vehicles/templates/vhc/vhc.html +++ b/vehicles/templates/vhc/vhc.html @@ -21,32 +21,34 @@