1. 버튼 만들기 + 버튼 누르면 custom view로 이동
@admin.register(MyModel)
class MyAdmin(BaseAdmin):
change_list_template = "custom_template.html"
def get_urls(self):
urls = super().get_urls()
info = self.model._meta.app_label, self.model._meta.model_name
custom_urls = [path("커스텀_view_url/", self.custom_view, name="%s_%s_statistic" % info)]
return custom_urls + urls
def custom_view(self, request):
model = self.model
cl = self.get_changelist_instance(request)
ctx = {
**self.admin_site.each_context(request),
"cl": cl,
"opts": cl.opts
}
return render(request, "버튼_누르면_이동할_템플릿.html", context=ctx)
2. custom_template.html
{% extends 'admin/change_list.html' %}
{% block object-tools %}
<div>
<a href="{% url "admin:커스텀_view_url" %}">이거 누르면 이동함</a>
</div>
<br/>
{{ block.super }}
{% endblock %}
3. 버튼누르면이동할_템플릿.html
{% extends "admin/base_site.html" %}
{% load i18n admin_urls static admin_list %}
{% block branding %}
<h1 id="site-name">
<a href="{% url 'admin:커스텀_view_url' %}">
{{ site_header|default:_('Django administration') }}
</a>
</h1>
{% endblock %}
{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% translate 'Home' %}</a>
› <a href="{% url 'admin:app_list' app_label=cl.opts.app_label %}">{{ cl.opts.app_config.verbose_name }}</a>
› <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>
› 내 커스텀 View {{ name }}
</div>
{% endblock %}
{% block content %}
이 부분을 마음 껏 꾸미셈
{% endblock %}