mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-11 04:19:25 +00:00
Election bdd + first view
This commit is contained in:
54
election/models.py
Normal file
54
election/models.py
Normal file
@ -0,0 +1,54 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils import timezone
|
||||
from django.conf import settings
|
||||
|
||||
from datetime import timedelta
|
||||
from core.models import User
|
||||
from subscription.models import Subscriber
|
||||
from subscription.views import get_subscriber
|
||||
|
||||
|
||||
class Election(models.Model):
|
||||
"""
|
||||
This class allow to create a new election
|
||||
"""
|
||||
title = models.CharField(_('title'), max_length=255)
|
||||
description = models.TextField(_('description'), null=True, blank=True)
|
||||
start_date = models.DateTimeField(_('start date'), blank=False)
|
||||
end_date = models.DateTimeField(_('end date'), blank=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
@property
|
||||
def is_active(self):
|
||||
now = timezone.now()
|
||||
return bool(now <= self.end_date and now >= self.start_date)
|
||||
|
||||
def get_results(self):
|
||||
pass
|
||||
|
||||
|
||||
class Responsability(models.Model):
|
||||
"""
|
||||
"""
|
||||
election = models.ForeignKey(Election, related_name='election', verbose_name=_("election"))
|
||||
title = models.CharField(_('title'), max_length=255)
|
||||
description = models.TextField(_('description'), null=True, blank=True)
|
||||
blank_votes = models.IntegerField(_('blank votes'), default=0)
|
||||
|
||||
def __str__(self):
|
||||
return ("%s : %s") % (self.election.title, self.title)
|
||||
|
||||
|
||||
class Candidate(models.Model):
|
||||
"""
|
||||
"""
|
||||
responsability = models.ForeignKey(Responsability, related_name='responsability', verbose_name=_("responsability"))
|
||||
subscriber = models.ForeignKey(Subscriber, verbose_name=_('user'), related_name='candidate', blank=True)
|
||||
program = models.TextField(_('description'), null=True, blank=True)
|
||||
votes = models.IntegerField(_('votes'), default=0)
|
||||
|
||||
def __str__(self):
|
||||
return ("%s : %s -> %s") % (self.election.title, self.title, self.subscriber.get_full_name())
|
Reference in New Issue
Block a user