summaryrefslogtreecommitdiff
path: root/polls/models.py
diff options
context:
space:
mode:
authoretienne2008-08-24 22:18:42 +0000
committeretienne2008-08-24 22:18:42 +0000
commitedd1bad62b445b0cae291f0406e7d0ca1eabf5ae (patch)
tree756cef4ae2ebcd104e2cb5e7e8bc958b547126cd /polls/models.py
parent95c2f32086b98edcdc1121bb936cfdefa1ee33bf (diff)
Update of the model. Sort vote by creation date (#15). Update of poll information (#13). New poll types (#2, #5)
Diffstat (limited to 'polls/models.py')
-rw-r--r--polls/models.py34
1 files changed, 23 insertions, 11 deletions
diff --git a/polls/models.py b/polls/models.py
index f4f1147..fd5f0a9 100644
--- a/polls/models.py
+++ b/polls/models.py
@@ -28,6 +28,7 @@ class PollUser(models.Model):
name = models.CharField(maxlength=100)
email = models.CharField(maxlength=100)
password = models.CharField(maxlength=100)
+ modification_date = models.DateTimeField(auto_now=True)
class Poll(models.Model):
name = models.CharField(maxlength=200)
@@ -35,35 +36,46 @@ class Poll(models.Model):
author = models.ForeignKey(PollUser)
base_url = models.CharField(maxlength=100)
admin_url = models.CharField(maxlength=100)
+ modification_date = models.DateTimeField(auto_now=True)
STATUS = (('A', _('Available')),
('D', _('Disabled')),)
status = models.CharField(maxlength=1, choices=STATUS)
- """TYPE = (('M', _('Meeting')),
- ('P', _('Poll')),
- ('B', _('Balanced poll')),
- ('O', _('One choice poll')),)"""
TYPE = (('P', _('Poll')),
- ('B', _('Balanced poll')),)
+ ('B', _('Balanced poll')),
+ ('O', _('One choice poll')),)
+ # ('M', _('Meeting')),)
type = models.CharField(maxlength=1, choices=TYPE)
def getTypeLabel(self):
idx = [type[0] for type in self.TYPE].index(self.type)
return Poll.TYPE[idx][1]
-
class Admin:
pass
+ class Meta:
+ ordering = ['-modification_date']
+
+class Voter(models.Model):
+ user = models.ForeignKey(PollUser)
+ poll = models.ForeignKey(Poll)
+ creation_date = models.DateTimeField(auto_now_add=True)
+ class Meta:
+ ordering = ['creation_date']
class Choice(models.Model):
poll = models.ForeignKey(Poll)
name = models.CharField(maxlength=200)
order = models.IntegerField()
+ limit = models.IntegerField()
+ available = models.BooleanField(default=True)
class Admin:
pass
+ class Meta:
+ ordering = ['order']
class Vote(models.Model):
- voter = models.ForeignKey(PollUser)
+ voter = models.ForeignKey(Voter)
choice = models.ForeignKey(Choice)
- VOTE = ((1, _('Yes')),
- (0, _('Maybe')),
- (-1, _('No')),)
- value = models.IntegerField(choices=VOTE) \ No newline at end of file
+ VOTE = ((1, (_('Yes'), _('Yes'))),
+ (0, (_('No'), _('Maybe')), ),
+ (-1, (_('No'), _('No'))),)
+ value = models.IntegerField(choices=VOTE, null=True) \ No newline at end of file