如何导出所有库?
使用
pip freeze >requirements.txt
导出所有库
pip install -r requirements.txt
安装所需的库
本地化设置-项目目录下的settings.py
设置language_code为zh-hans
设置time-zone为Asia/Shanghai
设置了2个模型类,一个为BlogType,博客分类,一个为博客模型
class BlogType(models.Model):
type_name = models.CharField(max_length=15)
def __str__(self):
return self.type_name
class Blog(models.Model):
title = models.CharField(max_length=50)
blog_type = models.ForeignKey(BlogType, on_delete=models.DO_NOTHING)
content = models.TextField()
author = models.ForeignKey(User, on_delete=models.DO_NOTHING)
created_time = models.DateTimeField(auto_now_add=True)
last_updated_time = models.DateTimeField(auto_now_add=True)
def __str__(self):
return "<Blog:%s>" % self.title
并在admin中应用
@admin.register(BlogType)
class BlogTypeAdmin(admin.ModelAdmin):
list_display = ('id', 'type_name')
@admin.register(Blog)
class BlogAdmin(admin.ModelAdmin):
list_display = ('title', 'blog_type', 'author', 'created_time', 'last_updated_time')