Advertisement
gotopa

models.py

Dec 4th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import datetime
  2.  
  3. from django.db import models
  4. from django.utils import timezone
  5. from django.utils.encoding import python_2_unicode_compatible
  6.  
  7. # Create your models here.
  8.  
  9. class Question(models.Model):
  10.     question_text = models.CharField(max_length=200)
  11.     pub_date = models.DateTimeField('date published')
  12.     def __str__(self):
  13.         return self.question_text
  14.     def was_published_recently(self):
  15.         return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
  16.  
  17.  
  18. class Choice(models.Model):
  19.     question = models.ForeignKey(Question, on_delete=models.CASCADE)
  20.     choice_text = models.CharField(max_length=200)
  21.     votes = models.IntegerField(default=0)
  22.     def __str__(self):
  23.         return self.choice_text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement