-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmodels.py
78 lines (55 loc) · 1.99 KB
/
models.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! -*- coding: utf-8 -*-
from django.db import models
from django.contrib.auth.models import User
class Poll(models.Model):
""" Poll
* Poll has question and description fields
"""
question = models.CharField('Question Name', max_length=255)
description = models.TextField('Description', blank=True)
""" Description field allows Blank """
null_field = models.CharField('Null Test', null=True, max_length=255)
blank_field = models.CharField('Blank Test', blank=True, max_length=255)
both_field = models.CharField('Both Test',
null=True, blank=True, max_length=255)
index_field = models.CharField('Index Test', db_index=True, max_length=255)
class Meta:
verbose_name = 'Poll'
class Genre(models.Model):
""" Genre
* Choice has genre
"""
name = models.CharField('Genre name', max_length=255)
class Meta:
verbose_name = 'Genre'
class Choice(models.Model):
""" Choice
* Choice has poll reference
* Choice has choices field
"""
CHOICES = (
(1, 'test1'),
(2, 'test2'),
(3, 'test3'),
)
poll = models.ForeignKey(Poll, verbose_name='Poll',
on_delete=models.CASCADE)
choice = models.SmallIntegerField('Choice', choices=CHOICES)
genres = models.ManyToManyField(Genre, verbose_name='Genre')
class Meta:
verbose_name = 'Choice'
class Vote(models.Model):
""" Vote
* Vote has user reference
* Vote has poll reference
* Vote has choice reference
"""
user = models.ForeignKey(User, verbose_name='Voted User',
on_delete=models.CASCADE)
poll = models.ForeignKey(Poll, verbose_name='Voted Poll',
on_delete=models.CASCADE)
choice = models.ForeignKey(Choice, verbose_name='Voted Choice',
on_delete=models.CASCADE)
class Meta:
verbose_name = 'Vote'
unique_together = (('user', 'poll'))