呀:)我可以;)
首先,你需要创建处理缩略图的自定义模板标签:
from django.template import Library
from django.utils.safestring import mark_safe
from django.contrib.admin.templatetags.admin_list import result_headers
register = Library()
def results(cl):
out = []
for item in cl.result_list:
url = cl.url_for_result(item)
code = '<a href="%(url)s">%(img)s</a> <div><a href="%(url)s">%(title)s</a></div>' % {
'url': url,
'img': item.preview.thumbnail_tag,
'title': item.title,
}
out.append(mark_safe(code))
return out
def gallery_result_list(cl):
return {'cl': cl,
'result_headers': list(result_headers(cl)),
'results': results(cl)}
result_list = register.inclusion_tag("admin/app_name/model/change_list_results.html")(gallery_result_list)
其中item.preview.thumbnail_tag是SORL创建的略图:) [我从默认的模板标签的原代码]
其次,你需要创建一个模板模型(使用新的自定义模板标签),那一定是在这个目录模式: templates_d IR /管理/ APP_NAME /模型/ change_list.html
,并有下面的代码:
{% extends "admin/change_list.html" %}
{% load adminmedia admin_list my_admin_tags i18n %}
{% block result_list %}
{% if action_form and actions_on_top and cl.full_result_count %}{% admin_actions %}{% endif %}
{% gallery_result_list cl %}
{% if action_form and actions_on_bottom and cl.full_result_count %}{% admin_actions %}{% endif %}
{% endblock %}
,你可以在你需要创建一个多个模板(称为change_list_result.html)的标签功能查看正确显示图像:
<style>
td.page { text-align: center; }
td.page a { font-weight: bold; }
</style>
{% if results %}
<table cellspacing="0">
<tbody>
<tr>
{% for result in results %}
<td class="page">
{{ result }}
</td>
{% if forloop.counter|divisibleby:3 %}
</tr><tr>
{% endif %}
{% endfor %}
</tr>
</tbody>
</table>
{% endif %}
所以在最后,你将有3个文件:
- templates_dir /管理/应用程序_name/MODEL_NAME/change_list.html
- templates_dir /管理/ APP_NAME /模型名称/ change_list_result.html
- your_project/APP_NAME/templatetags/my_admin_tags.py
,当然,templatetags必须添加到INSTALLED_APP在设置;)
这是所有;)希望这可能会有所帮助。