在覆盖django admin

时间:2019-11-19 06:45:03

标签: python django django-admin

我想在django管理员中添加一行,并为此自定义了django的change_list.html,但是在完成所有工作之后,我失去了以前的字段。

我以前有这个:Previous fields image

不是我想在页面的页脚中添加总计,而我得到了:

Image after customizing

我希望图像1和图像2在同一页面中。

@admin.register(Section4, site=admin_site)
class Section4Admin(ReadOnlyParamsMixin, admin.ModelAdmin):
    list_display = ['__str__', 'count_review', 'changelist_view']

    def count_review(self, obj):
     ......
     ......
     return mark_safe(
        render_to_string(
            "section4/count_review.html",
            {'id': obj.resident.id, 'counts': counts, 'completed': review_completed, 'to_add': review_not_added,
             })
    )
     change_list_template = 'section4/total_review_count.html'

    def get_total(self, user):
         ........
         .......
         return total_review_upto_date, total_review_tobe_updated, total_review_tobe_added
        def changelist_view(self, request, extra_context=None):
    total_review_upto_date, total_review_tobe_updated, total_review_tobe_added = self.get_total(request.user)
    my_context = {
        'total_review_upto_date': total_review_upto_date,
        'total_review_tobe_updated': total_review_tobe_updated,
        'total_review_tobe_added': total_review_tobe_added
    }
    return super(Section4Admin, self).changelist_view(request,
                                                     extra_context=my_context)

我有templates/admin/section4/section4/change_list.html

section4/templates/section4/total_review_count

{% extends "admin/change_list.html" %}
{% load i18n admin_urls %}
{% block result_list %}
 <footer> <p>The total review upto date: {{ total_review_upto_date}}<br> </p>
  <p>The total review to be updated: {{ total_review_tobe_updated}}<br></p>
  <p>Total review to be added : {{ total_review_tobe_added }}</p>
</footer>

{% endblock %}

0 个答案:

没有答案