1、運行django的指令:python manage.py runserver 二、建立項目 django-admin.py startproject mesite 三、建立應用 django-admin.py startapp blog 4、註冊應用 settings INSTALLED_APPS 5、根據數據庫模型創建數據庫表文件(至關於生成sql語句) python manage.py makemigrations 建立數據庫表 python manage.py migrate 六、建立超級管理員 python manage.py createsuperuser 登陸: 127.0.0.1:8000/admin 7、帶環境的shell python manage.py shell 八、獲取BookInfo.objects.all() BookInfo.objects.get(pk=1) 9、把模型類註冊到admin管理界面 admin.site.register(BookInfo) 10、fields和fieldsets是一個東西 保留一個就能夠了 class BookInfoAdmin(admin.ModelAdmin): # 列表頁 #顯示字段 點擊列頭可排序 list_display = ["pk", "btitle", 'bpub_date'] #過濾字段,過濾框會出如今右側 list_filter = ["btitle"] #搜索字段,搜索框會出如今上側 search_fields = ['btitle'] #分頁, 分頁框出如今下側 list_per_page = 5 #修改頁和添加頁 # 屬性分組 fieldsets = [ (u"基礎信息", {"fields": ['btitle']}), (u"時間信息", {"fields": ['bpub_date']}), ] class HeroInfoAdmin(admin.ModelAdmin): list_display = ["hname", "hgender", "hcontent", "hbook"] list_filter = ["hname"] search_fields = ["hname"] list_per_page = 5 fieldsets = [ ("base", {"fields": ['hname', 'hgender']}), ("more", {"fields": ['hcontent', 'hbook']}), ] admin.site.register(BookInfo, BookInfoAdmin) admin.site.register(HeroInfo, HeroInfoAdmin) 11、關聯註冊 class HeroInfoInline(admin.TabularInline): model = HeroInfo extra = 3 class BookInfoAdmin(admin.ModelAdmin): inlines = [HeroInfoInline] 12、路由 from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^', include('booktest.urls')), ] 1三、管理器是模型類的一個屬性,幫助模型類進行數據庫操做