• xadmin


    xadmin

    1.下载xadmin放在项目目录中,与static同级

    前往下载

    2.修改配置文件settings

    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'#更改
    

    3.修改路由

    import xadmin 
    
    urlpatterns = [
      # url(r'^admin/', admin.site.urls),注释原路由
      url(r'^xadmin/',include(xadmin.site.urls)),#添加新路由
    ]
    

    4.增加配置文件

    在每个APP目录下新建一个adminx.py文件

    1. models.py

      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
      
    2. adminx.py

      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)
      
  • 相关阅读:
    xhr
    原生js的博客
    webstorm调试Node的时候配置
    multiparty
    bluebird
    Nodejs+express+angularjs+mongodb
    mustache.js
    ModelProxy 前端接口配置建模框架
    浏览器跨域访问解决方案
    前端性能优化补充篇
  • 原文地址:https://www.cnblogs.com/liangchengyang/p/10621569.html
Copyright © 2020-2023  润新知