Last active
August 29, 2015 14:00
-
-
Save lihb/11072407 to your computer and use it in GitHub Desktop.
django admin.py 后台管理 示例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #coding:utf8 | |
| from django.contrib import admin | |
| from sqlTest.models import Publisher, Author, Book | |
| class AuthorAdmin(admin.ModelAdmin): | |
| list_display = ('first_name', 'last_name', 'email') # 页面显示元组中的信息 | |
| search_fields = ('first_name','last_name', 'email') # 左上角显示搜索栏 | |
| class BookAdmin(admin.ModelAdmin): | |
| list_display = ('title', 'publisher', 'publication_date') #显示可根据标签内容排序的表格 | |
| list_filter = ('publication_date', 'publisher') #页面右边显示一个快速查询器 | |
| date_hierarchy = 'publication_date' #页面左上角显示一个逐层深入的导航条 | |
| ordering = ('-publication_date',) #在'publication_date'标签上会出现一个倒三角形 | |
| #fields = ('title', 'authors', 'publisher') | |
| #filter_horizontal = ('authors',) | |
| raw_id_fields = ('publisher',) | |
| admin.site.register(Publisher) | |
| #admin.site.register(Author) | |
| admin.site.register(Author, AuthorAdmin) | |
| #admin.site.register(Book) | |
| admin.site.register(Book, BookAdmin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment