ええ:)私はできます;)
まず、サムネイルを処理するカスタムテンプレートタグを作成する必要があります。
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_dir / admin / app_name / model / 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 %}
タグ関数でわかるように、画像を正しく表示するには、もう1つのテンプレート(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つのファイルがあります。
- テンプレート_dir/admin / app_name / model_name / change_list.html
- template_dir / admin / app_name / model_name / change_list_result.html
- your_project / app_name / templatetags / my_admin_tags.py
そしてもちろん、テンプレートタグは設定でINSTALLED_APPに追加する必要があります;)
これがすべてです;)これがお役に立てば幸いです。