django xadmin
1.11.13版本下的[安装]:
1.下载分支版本
https://github.com/nocmt/Xadmin1.11.x/archive/master.zip
2.解压,并将其放在site-package下
然后在 settings.py文件的INSTALLED_APPS内添加以下代码:
INSTALLED_APPS = [ # 'django.contrib.admin', 'xadmin', 'crispy_forms', ]
3.修改urls.py文件
# from django.contrib import admin import xadmin urlpatterns = [ url(r'^xadmin/', xadmin.site.urls), ]
4.安装依赖库
pip install six future httplib2 django-reversion django-formtools django-crispy-forms
5.连接并创建表
python manage.py makemigrations python manage.py migrate
二[配置]:
1.后台展示字段的配置文件创建
1.1 在自己项目的app下创建adminx.py文件。
1.2 将同级目录下的admin.py文件内的内容复制到adminx.py内,原admin.py内的代码注释。
1.3 将 import admin 修改为 import xadmin,其余地方同理admin改为xadmin。
import xadmin from .models import Goods class GoodsAdmin(object): list_display = ["name", "click_num", "sold_num", "fav_num", "goods_num", "market_price", "shop_price", "goods_brief", "goods_desc", "is_new", "is_hot", "add_time"] search_fields = ['name', ] list_editable = ["is_hot", ] list_filter = ["name", "click_num", "sold_num", "fav_num", "goods_num", "market_price", "shop_price", "is_new", "is_hot", "add_time", "category__name"] xadmin.site.register(Goods, GoodsAdmin)
django2.0.5:
捷径:传送门https://github.com/sshwsfc/xadmin/tree/django2
直接
$ pip install https://codeload.github.com/sshwsfc/xadmin/zip/django2
1.xadmin的安装:
pip install xadmin 报错:'gbk' codec can't decode byte 0xa4 in position 3444
手动安装:
1)下载https://github.com/sshwsfc/xadmin
2)创建空文件覆盖README.rst
3)python setup.py install
2. 修改源码
1)from django.core.urlresolvers修改成了django.urls
2)外键添加on_delete=models.CASCADE参数
3)forms.Field.__init__(self, required, widget, label, initial, help_text, *args, **kwargs) 修改成 forms.Field.__init__(self)
4)from django.db.models.sql.query import LOOKUP_SEP, QUERY_TERMS 修改为
from django.db.models.sql.query import LOOKUP_SEP from django.db.models.sql.constants import QUERY_TERMS
5)if settings.LANGUAGES and ‘django.middleware.locale.LocaleMiddleware’ in settings.MIDDLEWARE_ClASSES:修改为
if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE:
6)login() got an unexpected keyword argument 'current_app'错误
#'current_app': self.admin_site.name,注释掉即可
7)'Media' object has no attribute 'add_css'
将util.py 中的86行 def vendor(*tags)修改 def vendor(*tags): css = {'screen': []} js = [] for tag in tags: file_type = tag.split('.')[-1] files = xstatic(tag) if file_type == 'js': js.extend(files) elif file_type == 'css': css['screen'] += files return Media(css=css, js=js)
3.终于跑起来了^-^