zoukankan      html  css  js  c++  java
  • Django 【admin】的一些功能实现

    设定后台系统名

    admin.AdminSite.site_header = '医院后台'
    

    添加自定义跳转按钮,添加新的列

    #整体内容参考https://simpleui.72wo.com/docs/simpleui/quick.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8C%89%E9%92%AE-action
    @admin.register(models.HospitalDepartmentModel)
    class HospitalDepartmentModelAdmin(admin.ModelAdmin):
    	#添加新的列
        def doctor_num(self, obj):
            num = obj.doctormodel_set.all().__len__()
            button_html = str(num)
            return format_html(button_html)
        doctor_num.short_description = '医生数量'
    
        list_display = ["id", "name", "department_description", "description","doctor_num"]
    	
    	#添加自定义按钮
        actions = ['custom_button']
        def custom_button(self, request, queryset):
            pass
        custom_button.type = 'info'
    	# 指定element-ui的按钮类型,参考https://element.eleme.cn/#/zh-CN/component/button
        custom_button.short_description = '跳转百度'
        custom_button.action_type = 2
    	#按钮动作类型,0=当前页内打开,1=新tab打开,2=浏览器tab打开
        custom_button.action_url = 'http://www.baidu.com'
    

    通过django-import-export实现导出功能

    参考原文档:https://django-import-export.readthedocs.io/en/latest/installation.html#settings

    1. 安装:pip install django-import-export
    2. 配置app,settings.py
      INSTALLED_APPS = [
      	...
      	'import_export',
      ]
      
    3. 配置admin.py
      from django.contrib import admin
      from main_app import models
      from import_export.admin import ImportExportModelAdmin
      # Register your models here.
      
      @admin.register(models.SleepAnalysisModel)
      class SleepAnalysisModelAdmin(ImportExportModelAdmin):
      	list_display = ["id", "height", "weight", "age", "gender", "sleep_time", "have_snore", ]
      
    4. 访问管理页面并尝试导出
  • 相关阅读:
    FactoryBean的作用
    ztree点击文字勾选checkbox,radio实现方法
    js判断字符长度 汉字算两个字符
    双系统引导修复
    thinkpadT440p
    分布式服务器集群
    Eclipse插件安装方式
    用SourceTree轻巧Git项目图解
    廖雪峰git使用完整教程
    hessian
  • 原文地址:https://www.cnblogs.com/lisicn/p/14953991.html
Copyright © 2011-2022 走看看