Advertisement
Broatlas

models.py (blog)

Mar 22nd, 2017
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. from django.db import models
  2. from django.utils import timezone
  3. import datetime
  4. from django.contrib.auth.models import User
  5. """
  6. The model for each created blog post
  7. """
  8. class BlogPost(models.Model):
  9.     title = models.CharField(max_length=50)
  10.     pub_date = models.DateTimeField('date published')
  11.     #publisher = models.ForeignKey(User, User.username) commented out not working
  12.     entry = models.TextField()
  13.     author = models.ForeignKey(User) #another attempt at linking the user creating the blog to the blog post
  14.  
  15.     def was_published_recently(self):
  16.         """
  17.         query to return the latest pblished blog post
  18.         """
  19.         return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
  20.  
  21.     def __str__(self):
  22.         return self.title
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement