models.py 672 B

1234567891011121314151617181920
  1. from django.db import models
  2. # 导入内建的User模型
  3. from django.contrib.auth.models import User
  4. # timezone用于处理时间相关的事物
  5. from django.utils import timezone
  6. # 博客文章数据模型
  7. class ArticlePost(models.Model):
  8. author = models.ForeignKey(User, on_delete=models.CASCADE)
  9. title = models.CharField(max_length=100)
  10. body = models.TextField()
  11. created = models.DateTimeField(default=timezone.now) #使用timezone.now()时 进行数据迁移会,有警告
  12. updated = models.DateTimeField(default=timezone.now)
  13. class Meta:
  14. ordering = ('-created',)
  15. def __str__(self):
  16. return self.title