问题
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