1
0

models.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from django.db import models
  2. from django.utils import timezone
  3. TSTATUT = [
  4. ('NOUVELLE', 'Nouvelle'),
  5. ('PROGRAMEE', 'Programmée'),
  6. ('ENCOUR', 'En cours'),
  7. ('FINI', 'Terminée'),
  8. ]
  9. TECH = [
  10. ('-', '* A def *'),
  11. ('LH', 'Laurent'),
  12. ('AC', 'Anthony'),
  13. ('PG', 'Philippe'),
  14. ]
  15. PRIO = [
  16. ('3', 'Urgent'),
  17. ('2', 'Important'),
  18. ('1', 'Normale'),
  19. ('0', 'Bas'),
  20. ]
  21. # Create your models here.
  22. class Taches(models.Model):
  23. Tache_Statut = models.CharField("Statut", max_length=16, choices=TSTATUT, default='NOUVELLE')
  24. Tache_Priorite = models.CharField("Priorité", max_length=16, choices=PRIO, default='1')
  25. Taches_Nom = models.CharField("Nom de la tache", max_length=128)
  26. Tache_GLPI = models.CharField("Url du GLPI Attaché", max_length=128, blank=True, default="" )
  27. Tache_Obj = models.CharField("Lié à", max_length=128, blank=True, default="")
  28. Taches_Commentaires = models.TextField("Explication")
  29. Taches_Tech = models.CharField("Technicien", max_length=16, choices=TECH, default='-')
  30. Tache_Date_Cree = models.DateTimeField("Date crée", auto_now_add=True)
  31. Tache_Date_Update = models.DateTimeField("Date de mise a jour", editable=False, blank=True, null=True)
  32. Tache_Date_Programee = models.DateTimeField("Date programmé", blank=True, null=True)
  33. Tache_Date_Terminee = models.DateTimeField("Date terminée", editable=False, blank=True, null=True)
  34. def __str__(self):
  35. return self.Taches_Nom
  36. def save(self, *args, **kwargs):
  37. self.Tache_Date_Terminee = timezone.now()
  38. if self.Tache_Statut == "FINI":
  39. self.Tache_Date_Terminee = timezone.now()
  40. elif self.Tache_Statut != "FINI" and self.Tache_Date_Terminee != None:
  41. self.Tache_Date_Terminee = None
  42. super(Taches, self).save(*args, **kwargs)
  43. class Meta:
  44. verbose_name = "Tache"
  45. verbose_name_plural = "Taches"