Django Admin覆盖-添加打印按钮 [英] Django admin overriding - adding a print button
问题描述
我想在django管理界面的应用程序内创建一个打印按钮,以将页面加载到另一个浏览器选项卡(已编码的视图)中,并让用户直接从管理界面进行打印。
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
我有一个名为 Card的模型,每个卡都有一个唯一的编号,用于加载相应的视图,现在我需要使用此编号并将其传递给打印按钮以重定向到我要打印的页面。
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?
我试过了
< a href = {{ROOT_URL}} / my_app / {{card.number}} class = historylink> Print< / a>
推荐答案
考虑使用django-object -actions应用程序,它允许将具有自定义逻辑的操作添加到django-admin。
Consider using django-object-actions app, it allows adding actions with custom logic to django-admin.
您可以在这里找到: https://github.com/texastribune/django-object-actions
You can find it here: https://github.com/texastribune/django-object-actions
安装:
1) pip install django-object-actions
2)添加 django_object_actions
到您的 INSTALLED_APPS
这篇关于Django Admin覆盖-添加打印按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!