Python 在管理页面中自定义模型的每一行

Python 在管理页面中自定义模型的每一行,python,django,Python,Django,我正在定制django管理模板 通过更改覆盖change\u list\u results.html和change\u list.html {% load i18n static %} {% if result_hidden_fields %} <div class="hiddenfields">{# DIV for HTML validation #} {% for item in result_hidden_fields %}{{ item }}{% endfor %} <

我正在定制django管理模板

通过更改覆盖
change\u list\u results.html
change\u list.html

{% load i18n static %}
{% if result_hidden_fields %}
<div class="hiddenfields">{# DIV for HTML validation #}
{% for item in result_hidden_fields %}{{ item }}{% endfor %}
</div>
{% endif %}
{% if results %}
<div class="results">
<table id="result_list">
<thead>
<tr> 
{% for header in result_headers %}
<th scope="col" {{ header.class_attrib }}>
   {% if header.sortable %}
     {% if header.sort_priority > 0 %}
       <div class="sortoptions">
         <a class="sortremove" href="{{ header.url_remove }}" title="{% trans "Remove from sorting" %}"></a>
         {% if num_sorted_fields > 1 %}<span class="sortpriority" title="{% blocktrans with priority_number=header.sort_priority %}Sorting priority: {{ priority_number }}{% endblocktrans %}">{{ header.sort_priority }}</span>{% endif %}
         <a href="{{ header.url_toggle }}" class="toggle {% if header.ascending %}ascending{% else %}descending{% endif %}" title="{% trans "Toggle sorting" %}"></a>
       </div>
     {% endif %}
   {% endif %}
   <div class="text">{% if header.sortable %}<a href="{{ header.url_primary }}">{{ header.text|capfirst }}</a>{% else %}<span>{{ header.text|capfirst }}</span>{% endif %}</div>
   <div class="clear"></div>
</th>{% endfor %}
</tr>
</thead>
<tbody>
{% for result in results %}
{% if result.form and result.form.non_field_errors %}
    <tr><td colspan="{{ result|length }}">{{ result.form.non_field_errors }}</td></tr>
{% endif %}
<tr class="{% cycle 'row1' 'row2' %}">{% for item in result %}{{ item }}{% endfor %}</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
但是现在我想自定义模型的每一行以关闭链接(我不想让用户进入每一行编辑页面)

我正在检查
change\u list\u result.html

{% load i18n static %}
{% if result_hidden_fields %}
<div class="hiddenfields">{# DIV for HTML validation #}
{% for item in result_hidden_fields %}{{ item }}{% endfor %}
</div>
{% endif %}
{% if results %}
<div class="results">
<table id="result_list">
<thead>
<tr> 
{% for header in result_headers %}
<th scope="col" {{ header.class_attrib }}>
   {% if header.sortable %}
     {% if header.sort_priority > 0 %}
       <div class="sortoptions">
         <a class="sortremove" href="{{ header.url_remove }}" title="{% trans "Remove from sorting" %}"></a>
         {% if num_sorted_fields > 1 %}<span class="sortpriority" title="{% blocktrans with priority_number=header.sort_priority %}Sorting priority: {{ priority_number }}{% endblocktrans %}">{{ header.sort_priority }}</span>{% endif %}
         <a href="{{ header.url_toggle }}" class="toggle {% if header.ascending %}ascending{% else %}descending{% endif %}" title="{% trans "Toggle sorting" %}"></a>
       </div>
     {% endif %}
   {% endif %}
   <div class="text">{% if header.sortable %}<a href="{{ header.url_primary }}">{{ header.text|capfirst }}</a>{% else %}<span>{{ header.text|capfirst }}</span>{% endif %}</div>
   <div class="clear"></div>
</th>{% endfor %}
</tr>
</thead>
<tbody>
{% for result in results %}
{% if result.form and result.form.non_field_errors %}
    <tr><td colspan="{{ result|length }}">{{ result.form.non_field_errors }}</td></tr>
{% endif %}
<tr class="{% cycle 'row1' 'row2' %}">{% for item in result %}{{ item }}{% endfor %}</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
{%load i18n static%}
{%if结果\隐藏\字段%}
{#用于HTML验证的DIV}
{result_hidden_fields%}{{item}{%endfor%}
{%endif%}
{%if结果%}
{result_headers%}中的头为%
{%if header.sortable%}
{%if header.sort_priority>0%}
{%if num_sorted_fields>1%}{{header.sort_priority}}{%endif%}
{%endif%}
{%endif%}
{%if header.sortable%}{%else%}{{header.text}{capfirst}{%endif%}
{%endfor%}
{结果中的结果为%}
{%if result.form和result.form.non_字段_错误%}
{{result.form.non_field_errors}
{%endif%}
{%for结果%}{{item}{%endfor%}
{%endfor%}
{%endif%}
并发现
{%for result%}{{item}{%endfor%}
输出了每一行

但是,如何自定义每个
项目


感谢您的帮助。

在django 1.7+中,您可以从管理模型的列表中删除链接:

class UsersAdmin(admin.ModelAdmin):
    list_display_links = None
但是,要知道这只会删除链接-如果用户能够找到相关的url,则不会阻止用户进入每行的查看/编辑页面。为此,您还需要处理该视图


请参见此处的一些讨论:

谢谢!!它击中了我的位置!