[Answer]-How to get an associated model via a custom admin action in Django?

1👍

✅

Just get the template field of your Report model:

def print_as_pdf(self, request, queryset):
    for report in queryset:
        markup = report.template.markup
        ...
print_as_pdf.short_description = 'Generate as pdf'

UPDATE: To use the logger you should add these two lines at the beginning of the source file:

import logging

logger = logging.getLogger(__name__)

Leave a comment