from django.db import models from django.utils import timezone TSTATUT = [ ('NOUVELLE', 'Nouvelle'), ('PROGRAMEE', 'Programmée'), ('ENCOUR', 'En cours'), ('FINI', 'Terminée'), ] TECH = [ ('-', '* A def *'), ('LH', 'Laurent'), ('AC', 'Anthony'), ('PG', 'Philippe'), ] PRIO = [ ('3', 'Urgent'), ('2', 'Important'), ('1', 'Normale'), ('0', 'Bas'), ] # Create your models here. class Taches(models.Model): Tache_Statut = models.CharField("Statut", max_length=16, choices=TSTATUT, default='NOUVELLE') Tache_Priorite = models.CharField("Priorité", max_length=16, choices=PRIO, default='1') Taches_Nom = models.CharField("Nom de la tache", max_length=128) Tache_GLPI = models.CharField("Url du GLPI Attaché", max_length=128, blank=True, default="" ) Tache_Obj = models.CharField("Lié à", max_length=128, blank=True, default="") Taches_Commentaires = models.TextField("Explication") Taches_Tech = models.CharField("Technicien", max_length=16, choices=TECH, default='-') Tache_Date_Cree = models.DateTimeField("Date crée", auto_now_add=True) Tache_Date_Update = models.DateTimeField("Date de mise a jour", editable=False, blank=True, null=True) Tache_Date_Programee = models.DateTimeField("Date programmé", blank=True, null=True) Tache_Date_Terminee = models.DateTimeField("Date terminée", editable=False, blank=True, null=True) def __str__(self): return self.Taches_Nom def save(self, *args, **kwargs): self.Tache_Date_Terminee = timezone.now() if self.Tache_Statut == "FINI": self.Tache_Date_Terminee = timezone.now() elif self.Tache_Statut != "FINI" and self.Tache_Date_Terminee != None: self.Tache_Date_Terminee = None super(Taches, self).save(*args, **kwargs) class Meta: verbose_name = "Tache" verbose_name_plural = "Taches"