1先在 models.py中,建立字段相關的內容,我這裏添加一個博客分類的表 定義數據結構的地方python
class PostType(models.Model): title = models.CharField(max_length = 60) #分類標題 order = models.IntegerField() #排序 timestamp = models.DateTimeField() #建立時間
2 執行數據庫同步數據庫
E:\python\mysite>python manage.py makemigrations blog Migrations for 'blog': blog\migrations\0004_posttype.py - Create model PostType
E:\python\mysite>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, blog, contenttypes, sessions
Running migrations:
Applying blog.0004_posttype... OK
3 經過Admin 管理django
經過Admin後臺來管理blog表數據。打開 admin.py 文件服務器
from django.contrib import admin from blog.models import BlogsPost from blog.models import Member from blog.models import Link from blog.models import PostType #這個是新添加的 # Register your models here. class BlogsPostAdmin(admin.ModelAdmin): list_display = ['title', 'body', 'timestamp'] class MemberAdmin(admin.ModelAdmin): list_display = ['username', 'password', 'timestamp'] class LinkAdmin(admin.ModelAdmin): list_display = ['title', 'link', 'order', 'timestamp'] class PostTypeAdmin(admin.ModelAdmin): list_display = ['title', 'order', 'timestamp'] #這個是新添加的 admin.site.register(BlogsPost, BlogsPostAdmin) admin.site.register(Member, MemberAdmin) admin.site.register(Link, LinkAdmin) admin.site.register(PostType, PostTypeAdmin) #這個是新添加的
4 重啓服務,打開後臺進行訪問session
5 若是想放到線上,那麼把文件都上傳到服務器,而後執行數據恢復數據結構
[root@izwz90bp6do7s3cr45cw6az newblog]# python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, blog, contenttypes, sessions
Running migrations:
Applying blog.0004_posttype... OK
6 重啓uwsgi,而後登錄後臺看下tcp
殺掉端口進程,從新加載post
fuser -k 8000/tcp
uwsgi --ini newblog.ini
7 登錄線上後臺看看測試
添加測試,能夠成功,有數據spa
OK,今天到這裏,下一步,看看怎麼把分類ID 弄到博客表裏面