Issue
I want to add a custom button right next to the SAVE button in my admin change form. I tried to add a button in submit_line.html
<input type="submit" action = "admin/{{id??}}" value="show PDF" name="show PDF{{ onclick_attrib }}/>
But, it doesn't redirect to my given page and I don't know how to pass the current id. Actually, I dont think it's a good idea to change submit_line.html anyways, because I only want it in one model. Is there a better solution for that?
Solution
I think you can add your own logic. Here you check app verbose name, to show that button only in your app:
{% if opts.verbose_name == 'Your app verbose name' %}<input type="submit" value="{% trans 'Show PDF' %}" name="_show_pdf" {{ onclick_attrib }}/>{% endif %}
and in your admin.py:
class YourAdmin(admin.ModelAdmin):
def response_change(self, request, obj):
if '_continue' in request.POST:
return HttpResponseRedirect(obj.get_admin_url())
elif '_show_pdf' in request.POST:
# Do some stuf here( show pdf in your case)
Answered By - wolendranh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.