from django.contrib.auth import get_user_model from django.db import models from gestion.models import ErnestoUser User = get_user_model() class Proposition(models.Model): name = models.CharField(max_length=100, verbose_name="nom du morceau") artist = models.CharField(blank=True, max_length=100) user = models.ForeignKey( ErnestoUser, on_delete=models.CASCADE, verbose_name="Proposé par" ) link = models.URLField(blank=True) nb_yes = models.IntegerField(default=0, verbose_name="nombre de réponses oui") nb_no = models.IntegerField(default=0, verbose_name="nombre de réponses non") def __str__(self): return self.name class Meta: verbose_name = "Proposition de morceau" verbose_name_plural = "Propositions de morceaux" class Answer(models.Model): YES = "oui" NO = "non" REP_CHOICES = [ (YES, "Oui"), (NO, "Non") ] proposition = models.ForeignKey(Proposition, on_delete=models.CASCADE) user = models.ForeignKey(User, on_delete=models.CASCADE) answer = models.CharField("Réponse", max_length=3, choices=REP_CHOICES) class Meta: unique_together = ("proposition", "user") verbose_name = "Réponse à une proposition" verbose_name_plural = "Réponses à une proposition"