how to django admin changlist add myself data

2023-02-18 14:26:39 浏览数 (1)

code:

# admin.py

代码语言:javascript复制
class BindBillAdmin(admin.ModelAdmin):
    def has_delete_permission(self, request, obj=None):
        # 编辑页面禁用删除按钮
        return False

    def has_add_permission(self, request, obj=None):
        # 编辑页面禁用 add 按钮
        return False

    # @csrf_protect_m
    def changelist_view(self, request, extra_context=None):
        extra_context = {
            "anchor_bill_total": 232131,
            "agent_earn": 2313131,
        }
        return super(BindBillAdmin, self).changelist_view(request, extra_context=extra_context)

    change_list_template = "change_list_custom.html"  # my_change_list_template

# change_list_custom.html(use django-simpleui)

代码语言:javascript复制
{% extends "admin/change_list.html" %}
{% load i18n admin_urls static admin_list %}


{% block content %}
    <style>
        #content {
            position: relative;
        }

        .object-tools {
            position: absolute;
            top: 16px;
            right: 20px;
            height: 50px;
            z-index: 2;
        }

        .object-tools .import_link, .object-tools .export_link {
            color: white !important;
        }

    </style>
    {% block object-tools %}
        <ul class="object-tools">
            {% block object-tools-items %}
                {% if has_add_permission %}
                    {{ block.super }}
                {% endif %}
            {% endblock %}
        </ul>
    {% endblock %}

    <div id="content-main">

        {% if cl.formset.errors %}
            <p class="errornote">
                {% if cl.formset.total_error_count == 1 %}{% trans "Please correct the error below." %}{% else %}
                    {% trans "Please correct the errors below." %}{% endif %}
            </p>
            {{ cl.formset.non_form_errors }}
        {% endif %}
        <div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
            {% block search %}{% search_form cl %}{% endblock %}
            {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}

            <form id="changelist-form" method="post"{% if cl.formset.is_multipart %}
                  enctype="multipart/form-data"{% endif %} novalidate>{% csrf_token %}
                {% if cl.formset %}
                    <div>{{ cl.formset.management_form }}</div>
                {% endif %}

                {% block result_list %}

                    {#                    {% if action_form %}#}
                    {% admin_actions %}
                    {#                    {% endif %}#}

                    {% result_list cl %}
                {% endblock %}
                {% block pagination %}{% pagination cl %}{% endblock %}
            </form>
            <div style="float: right;margin-right: 20px;">
                <p>主播累计流水:{{ anchor_bill_total }} <br>
                    代理累计收益:{{ agent_earn }}
                </p>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(".object-tools").hide().find('li a').each(function () {
            _action.exts.push({
                name: $(this).text(),
                url: $(this).attr('href')
            })
        })

    </script>
{% endblock %}

show:

0 人点赞