NSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'xadmin', #添加 'crispy_forms', #添加 ] # 語言配置 LANGUAGE_CODE = 'zh-hans'#更改 TIME_ZONE = 'Asia/Shanghai'#更改
import xadmin xadmin.autodiscover() from xadmin.plugins import xversion xversion.register_models() urlpatterns = [ # url(r'^admin/', admin.site.urls),註釋原路由 url(r'^xadmin/',include(xadmin.site.urls)),#添加新路由 ]
在每一個APP目錄下新建一個adminx.py文件python
models.pydjango
from django.db import models class User(models.Model): """用戶表""" name = models.CharField(max_length=32, verbose_name="姓名")#verbose_name在後臺顯示的字段名 gender = models.IntegerField(choices=Gender, verbose_name="性別") phone = models.CharField(max_length=11, verbose_name="手機號") email = models.CharField(max_length=64, verbose_name="郵箱") class Meta: verbose_name = '用戶' #verbose_name 在後臺顯示的表名 verbose_name_plural = verbose_name
adminx.pysession
import xadmin from apps.models import User class UserAdmin(object): list_display = ['name','gender','phone','email']#顯示信息的字段 search_fields = ['name','phone','email']#可查詢字段 list_filter = ['name']#能夠根據該字段過濾 xadmin.site.register(User,UserAdmin)
增長apps.py的內容app
from django.apps import AppConfig class DfUserConfig(AppConfig): name = 'df_user' verbose_name = "用戶"
增長__init__.py內容url
default_app_config='df_user.apps.DfOrderConfig'