from django.db import models
from datetime import date

class Evenement(models.Model):
    titre = models.CharField(max_length=200)
    date = models.DateField(default=date.today)
    heure_debut = models.TimeField(null=True, blank=True)
    heure_fin = models.TimeField(null=True, blank=True)
    lieu = models.CharField(max_length=200, blank=True)
    description = models.TextField(blank=True)

    @property
    def evenement_passe(self):
        return date.today() > self.date

    @property
    def annee(self):
        return self.date.year

    def __str__(self):
        return f"[{self.date}] {self.titre}"


class Illustration(models.Model):
    nom = models.CharField(max_length=200)
    image = models.ImageField(upload_to='timeline')
    evenement = models.ForeignKey(Evenement, on_delete=models.CASCADE)

    def __str__(self):
        return f"[{self.evenement}] {self.nom}"
