Django-admin:AdminDateWidget两次显示图标

时间:2018-10-18 08:22:29

标签: python django django-admin

我在Django-admin内创建了一个新的自定义页面。我在这里使用Django-admin的日期选择器。 Datepicker可以正常工作,但是它两次呈现日历图标和“ today” href:

enter image description here

您如何在不使用其他JS或CSS的情况下进行修复?

表格

class RequestAuditReportForm(forms.Form):
    date_from = forms.DateField(widget=AdminDateWidget())
    date_to = forms.DateField(widget=AdminDateWidget())

查看

class RequestAdminReportView(FormView):
    template_name = "main/reports/audit.html"
    form_class = RequestAuditReportForm

    def get_context_data(self, **kwargs):
        context = super().get_context_data()
        context.update({'opts': AuditOrder._meta,
                        'is_popup': False, 
                        'has_permission': True})
        return context

模板

{% extends "admin/base_site.html" %}
{% load i18n admin_urls static admin_list %}

{% block extrastyle %}
    {{ block.super }}
    <link rel="stylesheet" type="text/css" href="{% static "admin/css/changelists.css" %}">
    {% if cl.formset %}
        <link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}">
    {% endif %}
    {% if cl.formset or action_form %}
        <script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
    {% endif %}
    {{ media.css }}
    {% if not actions_on_top and not actions_on_bottom %}
        <style>
            #changelist table thead th:first-child {
                width: inherit
            }
        </style>
    {% endif %}
{% endblock %}

{% block extrahead %}
strong text
    {{ block.super }}

    {{ media.js }}
    <script type="text/javascript" src="/admin/jsi18n/"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="{% static 'admin/js/core.js' %}"></script>
    {#    <script type="text/javascript" src="{% static 'admin/js/admin/RelatedObjectLookups.js' %}"></script>#}

    <link rel="stylesheet" type="text/css" href="{% static 'admin/css/forms.css' %}"/>
    <link rel="stylesheet" type="text/css" href="{% static 'admin/css/base.css' %}"/>
    <link rel="stylesheet" type="text/css" href="{% static 'admin/css/widgets.css' %}"/>
    <script type="text/javascript" src="{% static 'admin/js/calendar.js' %}"></script>
    <script type="text/javascript" src="{% static 'admin/js/admin/DateTimeShortcuts.js' %}"></script>
    {{ form.media }}



{% endblock %}

{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} change-list{% endblock %}

{% if not is_popup %}
{% endif %}

{% block coltype %}flex{% endblock %}

{% block content %}
    <div id="content-main">
        {% block object-tools %}
            <ul class="object-tools">
                {% block object-tools-items %}
                    {% change_list_object_tools %}
                {% endblock %}
            </ul>
        {% endblock %}
        <form action="" method="post">{% csrf_token %}
            {{ form.as_p }}
            <button type="submit">Vygenerovať report</button>
        </form>
    </div>
{% endblock %}

1 个答案:

答案 0 :(得分:0)

也许是因为您在这里两次加载了js,

    <script type="text/javascript" src="{% static 'admin/js/calendar.js' %}"></script>
    <script type="text/javascript" src="{% static 'admin/js/admin/DateTimeShortcuts.js' %}"></script>
    {{ form.media }}