예 : I 수)
먼저 섬네일 처리하는 사용자 지정 템플릿 태그를 만들어야합니다
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에 의해 생성 된 thumnail입니다 :) [기본 템플릿 태그에서 원본 코드를 가져 왔습니다.]
두 번째로 (새 맞춤 템플릿 태그를 사용하는) 모델의 템플릿을 만들어야하며이 디렉토리 스키마에 있어야합니다 : 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)을 만들 필요가있는 태그 기능에서 볼 수 있듯이를 들어 이미지를 올바르게 표시 :
- templates_dir/관리자/응용 프로그램 :
<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 개 개의 파일이있을 것이다 _name/MODEL_NAME/change_list.html
- 이 templates_dir/관리/APP_NAME/MODEL_NAME/change_list_result.html
- your_project/APP_NAME/templatetags/my_admin_tags.py
을하고, 물론, templatetags이 INSTALLED_APP에 추가해야합니다 in 설정;)
이것은 모두;) 희망이 도움이 될 수 있습니다.