from django.db import models
from django.urls import reverse
from tinymce.models import HTMLField
from REUNION import settings
from reunions.models import Reunion


class Enquete(models.Model):

    intitule = models.CharField(max_length=255, null=True)
    reunion = models.ForeignKey(Reunion, null=True, on_delete=models.CASCADE)
    cible = models.CharField(max_length=50, null=True, blank=True)
    acteurs = models.CharField(max_length=255, null=True)
    lieu = models.CharField(max_length=255)
    indicateurs = HTMLField(null=True)
    description = HTMLField(null=True)
    periode = models.CharField(max_length=255)
    link_surveycto = models.URLField(blank=True, null=True)
    datesysteme = models.DateTimeField(auto_now_add=True)
    created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING, null=True,
                                   verbose_name='Créé par')

    def get_absolute_url(self):
        return reverse('enquete:detail_enquete', args=[self.id])

    def __str__(self):
        return  f"{self.cible} - {self.acteurs}"

    class Meta:
        ordering = ['-datesysteme']
        indexes = [
            models.Index(fields=['-datesysteme','periode']),
        ]