models.py 946 B

123456789101112131415161718192021222324252627282930313233
  1. from __future__ import unicode_literals
  2. from django.db import models
  3. from django.utils import timezone
  4. # Create your models here.
  5. class Post(models.Model):
  6. '''
  7. A standard blog post.
  8. '''
  9. title = models.CharField(max_length=255)
  10. content = models.TextField()
  11. pub_date = models.DateTimeField(default=timezone.now, editable=False)
  12. last_edited = models.DateTimeField(auto_now=True, blank=True)
  13. def __unicode__(self):
  14. return self.title
  15. class Comment(models.Model):
  16. '''
  17. A comment to be made on a blog post.
  18. '''
  19. author = models.CharField(max_length=255)
  20. website = models.CharField(max_length=255, blank=True)
  21. pub_date = models.DateTimeField(default=timezone.now, editable=False)
  22. content = models.TextField()
  23. post = models.ForeignKey(Post, on_delete=models.CASCADE)
  24. def __unicode__(self):
  25. return u"%s on \"%s\" (%s)" % (self.author, self.post.title, self.pub_date)