我需要访问用于在change_list.html中生成列表的查询集(包括过滤,搜索等)
这在Django 2.2.1和Python 3.6中
admin.py
class CompanyAdmin(admin.ModelAdmin):
list_display = ('name', 'city')
list_display_links = ('name', 'city')
list_filter = ('city', )
search_fields = ('name', )
change_list_template = 'admin/contacts/company/change_list.html'
admin.site.register(Company, CompanyAdmin)
change_list.html
{% extends "admin/change_list.html" %}
{% block content %}
{{ block.super }}
{% endblock %}
我想实现这样的目标:
{% block content %}
{% for item in list %}
//and there iterate over all items of list
{% endfor %}
{{ block.super }}
{% endblock %}
答案 0 :(得分:0)
答案是
{% block content %}
{% for item in cl.queryset %}
{{ item }}
{% endfor %}
{{ block.super }}
{% endblock %}
它是查询列表