Django-suit 安装和部署
1. pip install Django-suit
2. 将’suit’加到INSTALLED_APPS中,suit 必须在所有管理APP之前。
3. 将django.template.context_processors.request 加到TEMPLATES->OPTIONS->context_processors设置中,用于左侧的menu菜单的处理。
4. 部署见Djangodocs on wsgi。
模板
1. 模板文件base_site.html需要拷到任意的模板路径中(tempaltes/admin/ 或TEMPLATE_DIRS设置中)
2. 例子见github
3. 自定义模板DjangoAdmin Tutorial
设置
# 配置的默认选项和解释如下
1. SUIT_CONFIG = {
2. # header 网页头部显示选项
3. # 'ADMIN_NAME': 'Django Suit', 左侧标题
4. # 'HEADER_DATE_FORMAT': 'l, j. F Y', 日期格式见Django日期格式说明
5. # 'HEADER_TIME_FORMAT': 'H:i',
6.
7. # forms 表单相关
8. # 'SHOW_REQUIRED_ASTERISK': True, # Default True 必填的表单项显示星号
9. # 'CONFIRM_UNSAVED_CHANGES': True, # Default True 未保存时提示是否保存
10.
11. # menu 左侧菜单相关
12. # 'SEARCH_URL': '/admin/auth/user/', 搜索时默认的url
13. # 'MENU_ICONS': {
14. # 'sites': 'icon-leaf', 暂不明确
15. # 'auth': 'icon-lock',
16. # },
17. # 'MENU_OPEN_FIRST_CHILD': True, # Default True 点击菜单时打开其第一个子菜单
18. # 'MENU_EXCLUDE': ('auth.group',), 将app或其model不在menu菜单中显示
19. # 'MENU': (
20. # 'sites', 暂不明确
21. # {'app': 'auth', 'icon':'icon-lock', 'models': ('user', 'group')}, 验证app
22. # {'label': 'Settings', 'icon':'icon-cog', 'models': ('auth.user', 'auth.group')} 自定义app,设置其菜单名,图标,所包含的models,或只是一个链接
23. # {'label': 'Support', 'icon':'icon-question-sign', 'url': '/support/'},
24. # ),
25.
26. # misc
27. # 'LIST_PER_PAGE': 15 changelist每页显示的最大条目数
Widgets
相关的类:class model, class ModelForm, class ModelAdmin
这里建立Country 菜单项为例,展示如何在管理控制台中添加相应的控制页面。
step1:建立数据模型 model.py
1. class Country(models.Model):
2. name = models.CharField(max_length=256)
3. code = models.CharField(max_length=2,
4. help_text='ISO 3166-1 alpha-2 - two character '
5. 'country code')
6. independence_day = models.DateField(blank=True, null=True)
7. continent = models.ForeignKey(Continent, null=True)
8. area = models.BigIntegerField(blank=True, null=True)
9. population = models.BigIntegerField(blank=True, null=True)
10. order = models.PositiveIntegerField(default=0)
11. description = models.TextField(blank=True,
12. help_text='Try and enter few some more '
13. 'lines')
14. architecture = models.TextField(blank=True)
15.
16. def __unicode__(self):