Django admin overriding - adding a print button

十年热恋 提交于 2019-12-13 10:17:39

问题


I would like to create a "print button" inside an app in django admin interface to load a page in another browser tab (a view that is already coded) and let the user print it directly from admin interface.

I used the override to add a "print" button near the "history" button following this example: overriding admin templates

I have a model named "Card", each card has a unique number which is used to load a corresponding view, now I need to take this number and pass it to the print button to redirect to the page I want to print. How to get it?

I tried this

<a href="{{ ROOT_URL }}/my_app/{{ card.number }}" class="historylink">Print</a>

but it redirect to the root directory and doesn't take the value I need from the model.


回答1:


Consider using django-object-actions app, it allows adding actions with custom logic to django-admin.

You can find it here: https://github.com/texastribune/django-object-actions

Installlation:

1) pip install django-object-actions

2) add django_object_actions to your INSTALLED_APPS



来源:https://stackoverflow.com/questions/19476195/django-admin-overriding-adding-a-print-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!