You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
class Poll(
|
|
|
|
models.Model,
|
|
|
|
):
|
|
|
|
question = models.TextField(
|
|
|
|
max_length=250,
|
|
|
|
help_text="Question to ask the user",
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(
|
|
|
|
self,
|
|
|
|
):
|
|
|
|
return f"Poll: {self.question}"
|
|
|
|
|
|
|
|
|
|
|
|
class Option(
|
|
|
|
models.Model,
|
|
|
|
):
|
|
|
|
poll = models.ForeignKey(
|
|
|
|
Poll,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
)
|
|
|
|
text = models.TextField(
|
|
|
|
max_length=100,
|
|
|
|
help_text="Poll Option",
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(
|
|
|
|
self,
|
|
|
|
):
|
|
|
|
return f"Option for {self.poll}: {self.text}"
|
|
|
|
|
|
|
|
|
|
|
|
class Vote(
|
|
|
|
models.Model,
|
|
|
|
):
|
|
|
|
user = models.ForeignKey(
|
|
|
|
User,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
)
|
|
|
|
poll = models.ForeignKey(
|
|
|
|
Poll,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
)
|
|
|
|
option = models.ForeignKey(
|
|
|
|
Option,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(
|
|
|
|
self,
|
|
|
|
):
|
|
|
|
return f"Vote by {self.user} for {self.poll} - Option:{self.option}"
|