ernestophone.ens.fr/propositions/models.py
Martin Pépin 5381aba922
Remove the nb_{yes,no} fields
These fields duplicate information that is already present in the Answer
table. I guess they exist(ed) as an optimisation to avoid recomputing
the number of positive and negative answers per proposition each time
the list page is loaded. Given the small number of propositions we have
in practice and the extra housekeeping required to keep these fields up
to date, I consider simplicity matters more here.
2020-01-05 16:34:10 +01:00

37 lines
1.1 KiB
Python

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)
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"