在覆盖Django admin的change_list.html时丢失了以前的值

2024-04-23 10:56:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在django admin中添加一行,为此我定制了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 %}

Tags: toselfaddeddateadminhtmlcountchange