zoukankan      html  css  js  c++  java
  • admin

    from django.contrib import admin
    from app01 import models
    from .utils.to_excel import to_excel
    
    # Register your models here.
    
    
    class StudentAdmin(admin.ModelAdmin):
        """配置后台显示的内容  传给注册信息"""
        list_display = ('name', 'age', 'gender', 'phone', 'height', 'weight', 'school', 'grade', 'create_date')  # 显示的字段
        # list_editable = ('phone', )  # 可编辑的字段,M2M不能设为可编辑
        # filter_horizontal = ('name',)  # 查询框,M2M
        # list_per_page = (3)#设置分页
        search_fields = ('name', 'age', 'gender')  # 可以以哪些字段搜索
        list_filter = ('create_date', 'school', 'grade')  # 设置分类查询
        # ordering = ('-id',)  # 设置默认以哪个字段排序('-id',)降序
        # fieldsets = [  # 显示部分字段,其余折叠
        #     (None, {'fields': ['name']}),
        #     ('price information', {'fields': ['price', "publish", 'pub_date', 'authors'], 'classes': ['collapse']}),
        # ]
        add_form_template = ''
    
        def export(self, request, queryset):
            """
            下拉框多选操作,导出选中内容至excel
            :param request:request
            :param queryset: 选中的数据
            :return:
            """
            to_excel(queryset)
    
        export.short_description = '导出'  # 下拉框显示的信息,func为执行的操作
        actions = [export, ]
    
    
    admin.site.register(models.StudentInfo, StudentAdmin)
    admin.site.register(models.School)
  • 相关阅读:
    1052 Linked List Sorting (25 分)
    1051 Pop Sequence (25 分)
    1050 String Subtraction (20 分)
    1049 Counting Ones (30 分)
    1048 Find Coins (25 分)
    1047 Student List for Course (25 分)
    1046 Shortest Distance (20 分)
    1045 Favorite Color Stripe (30 分)
    1044 Shopping in Mars (25 分)
    1055 The World's Richest (25 分)
  • 原文地址:https://www.cnblogs.com/webc/p/9521238.html
Copyright © 2011-2022 走看看