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