Django外键约束管理
Xadmin添加小组件报错
def render(self, name, value, attrs=None):
def render(self, name, value, attrs=None, renderer=None):
Xadmin基础配置
class BaseSetting(object):
enable_themes = True
use_bootswatch = True
class GlobalSettings(object):
site_title = '塞拉菲娜管理后台'
site_footer = 'Powered by: 塞拉菲娜'
site_url = '/'
menu_style = 'accordion'
xadmin.site.register(xviews.CommAdminView, GlobalSettings)
xadmin.site.register(xviews.BaseAdminView, BaseSetting)
from xadmin.plugins.actions import BaseActionViewclass MyAction(BaseActionView):
action_name = "my_action"
description = _(u'Test selected %(verbose_name_plural)s')
model_perm = 'change'
def do_action(self, queryset):
for obj in queryset:
...
return HttpResponse(...)
class MyModelAdmin(object):
actions = [MyAction, ]
list_filter 属性:
search_fields 属性:
free_query_filter 属性:
http://xxx.com/xadmin/auth/user/?name__contains=tony
class UserAdmin(object):
list_filter = ('is_staff', 'is_superuser', 'is_active', 'user_id__name')
search_fields = ('username', 'first_name', 'last_name', 'email')
"""
title : 图表的显示名称
x-field : 图表的 X 轴数据列, 一般是日期, 时间等
y-field : 图表的 Y 轴数据列, 该项是一个 list, 可以同时设定多个列, 这样多个列的数据会在同一个图表中显示
order : 排序信息, 如果不写则使用数据列表的排序
"""
class RecordAdmin(object):
data_charts = {
"user_count": {'title': u"User Report", "x-field": "date", "y-field": ("user_count", "view_count"), "order": ('date',)},
"avg_count": {'title': u"Avg Report", "x-field": "date", "y-field": ('avg_count',), "order": ('date',)}
}
show_bookmarks 属性:
list_bookmarks 属性:
class UserAdmin(object):
list_bookmarks = [{
'title': "Female",
'query': {'gender': True},
'order': ('-age'),
'cols': ('first_name', 'age', 'phones'),
'search': 'Tom'
}, {...}
]
class MyModelAdmin(object):
list_export = ('xls', xml', 'json')
class MyModelAdmin(object):
refresh_times = (3, 5)
"""
使用该插件主要设置 OptionClass 的 show_detail_fields, show_all_rel_details 两个属性. show_detail_fields属性设置哪些字段要显示详细信息, show_all_rel_details 属性设置时候自动显示所有关联字段的详细信息, 该属性默认为 True. 示例如下:
"""
class MyModelAdmin(object):
show_detail_fields = ['group', 'father', ...]
"""
使用该插件主要设置 OptionClass 的 list_editable 属性. list_editable 属性设置哪些字段需要即时修改功能.
"""
class MyModelAdmin(object):
list_editable = ['price', 'status', ...]