Update model
Browse files- app/polls/models.py +12 -2
app/polls/models.py
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
|
|
| 1 |
from django.db import models
|
| 2 |
-
|
| 3 |
|
| 4 |
class Question(models.Model):
|
| 5 |
question_text = models.CharField(max_length=200)
|
| 6 |
pub_date = models.DateTimeField('date published')
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
class Choice(models.Model):
|
| 10 |
question = models.ForeignKey(Question, on_delete=models.CASCADE)
|
| 11 |
choice_text = models.CharField(max_length=200)
|
| 12 |
-
votes = models.IntegerField(default=0)
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
from django.db import models
|
| 3 |
+
from django.utils import timezone
|
| 4 |
|
| 5 |
class Question(models.Model):
|
| 6 |
question_text = models.CharField(max_length=200)
|
| 7 |
pub_date = models.DateTimeField('date published')
|
| 8 |
|
| 9 |
+
def __str__(self):
|
| 10 |
+
return self.question_text
|
| 11 |
+
|
| 12 |
+
def was_published_recently(self):
|
| 13 |
+
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
|
| 14 |
+
|
| 15 |
|
| 16 |
class Choice(models.Model):
|
| 17 |
question = models.ForeignKey(Question, on_delete=models.CASCADE)
|
| 18 |
choice_text = models.CharField(max_length=200)
|
| 19 |
+
votes = models.IntegerField(default=0)
|
| 20 |
+
|
| 21 |
+
def __str__(self):
|
| 22 |
+
return self.choice_text
|