You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.py 547B

123456789101112131415161718
  1. from django.conf import settings
  2. from django.db import models
  3. from django.utils import timezone
  4. class Post(models.Model):
  5. author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
  6. title = models.CharField(max_length=200)
  7. text = models.TextField()
  8. created_date = models.DateTimeField(default=timezone.now)
  9. published_date = models.DateTimeField(blank=True, null=True)
  10. def publish(self):
  11. self.published_date = timezone.now()
  12. self.save()
  13. def __str__(self):
  14. return self.title