Advertisement
Guest User

Untitled

a guest
Apr 4th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. import datetime
  2.  
  3. from django.db import models
  4. from django.utils import timezone
  5.  
  6.  
  7. class Question(models.Model):
  8.     file_obj = models.FileField(null=True)
  9.     question_text = models.CharField(max_length=200)
  10.     pub_date = models.DateTimeField('date published')
  11.  
  12.     def __str__(self):
  13.         return self.question_text
  14.  
  15.     def was_published_recently(self):
  16.         now = timezone.now()
  17.         return now - datetime.timedelta(days=1) <= self.pub_date <= now
  18.     was_published_recently.admin_order_field = 'pub_date'
  19.     was_published_recently.boolean = True
  20.     was_published_recently.short_description = 'Published recently?'
  21.  
  22.  
  23. class Choice(models.Model):
  24.     question = models.ForeignKey(Question, on_delete=models.CASCADE)
  25.     choice_text = models.CharField(max_length=200)
  26.     votes = models.IntegerField(default=0)
  27.  
  28.     def __str__(self):
  29.         return self.choice_text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement