New bdd arch

This commit is contained in:
Antoine Bartuccio 2016-12-13 22:11:06 +01:00
parent fd3309fc5f
commit d14af8e452

View File

@ -15,8 +15,8 @@ class Election(models.Model):
""" """
title = models.CharField(_('title'), max_length=255) title = models.CharField(_('title'), max_length=255)
description = models.TextField(_('description'), null=True, blank=True) description = models.TextField(_('description'), null=True, blank=True)
start_proposal = models.DateTimeField(_('start proposal'), blank=False) start_candidature = models.DateTimeField(_('start candidature'), blank=False)
end_proposal = models.DateTimeField(_('end proposal'), blank=False) end_candidature = models.DateTimeField(_('end candidature'), blank=False)
start_date = models.DateTimeField(_('start date'), blank=False) start_date = models.DateTimeField(_('start date'), blank=False)
end_date = models.DateTimeField(_('end date'), blank=False) end_date = models.DateTimeField(_('end date'), blank=False)
@ -29,22 +29,22 @@ class Election(models.Model):
return bool(now <= self.end_date and now >= self.start_date) return bool(now <= self.end_date and now >= self.start_date)
@property @property
def is_proposal_active(self): def is_candidature_active(self):
now = timezone.now() now = timezone.now()
return bool(now <= self.end_proposal and now >= self.start_proposal) return bool(now <= self.end_candidature and now >= self.start_candidature)
def has_voted(self, user): def has_voted(self, user):
return self.vote.filter(user__id=user.id).exists() return self.has_voted.filter(id=user.id).exists()
def get_results(self): def get_results(self):
pass pass
class Responsability(models.Model): class Role(models.Model):
""" """
This class allows to create a new responsability This class allows to create a new role avaliable for a candidature
""" """
election = models.ForeignKey(Election, related_name='responsability', verbose_name=_("election")) election = models.ForeignKey(Election, related_name='role', verbose_name=_("election"))
title = models.CharField(_('title'), max_length=255) title = models.CharField(_('title'), max_length=255)
description = models.TextField(_('description'), null=True, blank=True) description = models.TextField(_('description'), null=True, blank=True)
@ -52,25 +52,29 @@ class Responsability(models.Model):
return ("%s : %s") % (self.election.title, self.title) return ("%s : %s") % (self.election.title, self.title)
class Candidate(models.Model): class Candidature(models.Model):
""" """
This class is a component of responsability This class is a component of responsability
""" """
responsability = models.ForeignKey(Responsability, related_name='candidate', verbose_name=_("responsability")) role = models.ForeignKey(Role, related_name='candidature', verbose_name=_("role"))
user = models.ForeignKey(User, verbose_name=_('user'), related_name='candidate', blank=True) user = models.ForeignKey(User, verbose_name=_('user'), related_name='candidate', blank=True)
program = models.TextField(_('description'), null=True, blank=True) program = models.TextField(_('description'), null=True, blank=True)
has_voted = models.ManyToManyField(User, verbose_name=_('has_voted'), related_name='has_voted')
def __str__(self):
return ("%s : %s -> %s") % (self.election.title, self.title, self.user.get_full_name()) class List(models.Model):
"""
To allow per list vote
"""
title = models.CharField(_('title'))
class Vote(models.Model): class Vote(models.Model):
""" """
This class allows to vote for candidates This class allows to vote for candidates
""" """
election = models.ForeignKey(Election, related_name='vote', verbose_name=_("election")) role = models.ForeignKey(Role, related_name='vote', verbose_name=_("role"))
candidate = models.ManyToManyField(Candidate, related_name='vote', verbose_name=_("candidate")) candidature = models.ManyToManyField(Candidature, related_name='vote', verbose_name=_("candidature"))
user = models.ForeignKey(User, related_name='vote', verbose_name=_("user"))
def __str__(self): def __str__(self):
return "Vote" return "Vote"