models.py 545 B

12345678910111213141516171819
  1. from django.db import models
  2. from django.utils import timezone
  3. # Create your models here.
  4. class Post(models.Model):
  5. author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
  6. title = models.CharField(max_length=200)
  7. text = models.TextField()
  8. create_date = models.DateTimeField(
  9. default=timezone.now)
  10. published_date = models.DateTimeField(
  11. blank=True, null=True)
  12. def publish(self):
  13. self.published_date = timezone.now()
  14. self.save()
  15. def __str__(self):
  16. return self.title