site_tps/vote/models.py

23 lines
718 B
Python
Raw Normal View History

2018-01-14 12:19:11 +00:00
from django.db import models
from django.core import validators
2018-01-22 13:10:37 +00:00
from content.models import Content
from django.contrib.auth.models import Group, User
2018-01-21 00:10:32 +00:00
2018-01-22 21:11:16 +00:00
class Poll(models.Model):
voters_group = models.ForeignKey(Group, on_delete=models.CASCADE)
contents = models.ManyToManyField(Content)
title = models.CharField(max_length=1024)
2018-01-21 00:10:32 +00:00
class Vote(models.Model):
2018-01-22 13:10:37 +00:00
votant = models.ForeignKey(User, on_delete=models.CASCADE)
content = models.ForeignKey(Content, on_delete=models.CASCADE)
2018-01-22 21:11:16 +00:00
poll = models.ForeignKey(Poll, on_delete=models.CASCADE)
vote = models.IntegerField(
2018-01-21 00:10:32 +00:00
validators=[
validators.MaxValueValidator(5),
validators.MinValueValidator(0)
]
)