from django.db import models
from django.conf import settings
# Create your models here.


class Question(models.Model):
    author = models.ForeignKey(
        settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ['-pub_date']

    def __str__(self):
        return self.question_text


class Choice(models.Model):
    question = models.ForeignKey(
        Question, on_delete=models.CASCADE, null=True, blank=True)
    choice_text = models.CharField(max_length=50)
    votes = models.IntegerField(default=0)

    class Meta:
        ordering = ['-votes']

    def __str__(self):
        return self.choice_text
