summaryrefslogtreecommitdiff
path: root/polls/models.py
blob: 08395b87de065cf9c281b8c963d72e7d0e4912b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2008  Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet>
# This program can be distributed under the terms of the GNU GPL.
# See the file COPYING.

from django.db import models

class PollUser(models.Model):
    name = models.CharField(maxlength=100)
    email = models.CharField(maxlength=100)
    password = models.CharField(maxlength=100)

class Poll(models.Model):
    name = models.CharField(maxlength=200)
    description = models.CharField(maxlength=1000)
    author = models.ForeignKey(PollUser)
    base_url = models.CharField(maxlength=100)
    admin_url = models.CharField(maxlength=100)
    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 = 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 Choice(models.Model):
    poll = models.ForeignKey(Poll)
    name = models.CharField(maxlength=200)
    order = models.IntegerField()
    class Admin:
        pass

class Vote(models.Model):
    voter = models.ForeignKey(PollUser)
    choice = models.ForeignKey(Choice)
    VOTE = ((-1, 'No'), 
            (0, 'Maybe'),
            (1, 'Yes'),)
    value = models.IntegerField(choices=VOTE)