码迷,mamicode.com
首页 > 其他好文 > 详细

Django实践:个人博客系统(第八章 admin的配置)

时间:2016-01-19 17:17:12      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

如何配置使用django admin?
1、在INSTALLED_APPS中添加django.contrib.admin
2、配置urls.py
url(r‘^admin/‘, include(admin.site.urls))
3、在admin注册的Model,(默认方式和自定义方式),注意model中关于admin的一些配置

fields\exclude

自定义管理类AritcleAmin,并添加在注册中。作用:添加文章的时候只显示fields中的三列。exclude则出去相应列

from django.contrib import admin
from models import *
# Register your models here.

class AritcleAdmin(admin.ModelAdmin):

    fields = (title, desc, content)


admin.site.register(User)
admin.site.register(Tag)
admin.site.register(Article, AritcleAdmin)
admin.site.register(Category)
admin.site.register(Comment)
admin.site.register(Links)
admin.site.register(Ad)

 


fieldsets

# -*- coding:utf-8 -*-
from django.contrib import admin
from models import *
# Register your models here.

class AritcleAdmin(admin.ModelAdmin):

    fieldsets = (
        (None, {
            fields: (title, desc, content,)
        }),
        (高级设置,{
            classes: (collapse,),
            fields: (click_count, is_recommend,)
        }),
    )


admin.site.register(User)
admin.site.register(Tag)
admin.site.register(Article, AritcleAdmin)
admin.site.register(Category)
admin.site.register(Comment)
admin.site.register(Links)
admin.site.register(Ad)

效果技术分享


list_display

# -*- coding:utf-8 -*-
from django.contrib import admin
from models import *
# Register your models here.

class AritcleAdmin(admin.ModelAdmin):

    list_display = (title, desc, click_count,)

    ‘‘‘fieldsets = (
        (None, {
            ‘fields‘: (‘title‘, ‘desc‘, ‘content‘,)
        }),
        (‘高级设置‘,{
            ‘classes‘: (‘collapse‘,),
            ‘fields‘: (‘click_count‘, ‘is_recommend‘,)
        }),
    )‘‘‘


admin.site.register(User)
admin.site.register(Tag)
admin.site.register(Article, AritcleAdmin)
admin.site.register(Category)
admin.site.register(Comment)
admin.site.register(Links)
admin.site.register(Ad)

效果(默认只显示一列):    

技术分享

list_display_links

class AritcleAdmin(admin.ModelAdmin):

    list_display = (title, desc, click_count,)
    list_display_links = (title, desc, click_count,)

效果:在其中添加的列可以链接到编辑页面

技术分享


list_editable

class AritcleAdmin(admin.ModelAdmin):

    list_display = (title, desc, click_count,)
    list_display_links = (title, desc, )
    list_editable = (click_count,)

效果:使相应列可编辑,但此列不能同时放入list_display_links和list_editable中。添加此属性后右下角会有保存按钮

技术分享
list_filter
inlines
...

参考资料:
https://docs.djangoproject.com/en/1.8/ref/contrib/admin/

xadmin

扩展阅读:admindocs的使用
https://docs.djangoproject.com/en/1.8/ref/contrib/admin/admindocs/

 

Django实践:个人博客系统(第八章 admin的配置)

标签:

原文地址:http://www.cnblogs.com/songbird/p/5142695.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!