I have found that
https://github.com/django/django/raw/stable/3.0.x/django/contrib/admin/templates/admin/change_form.html consists of the code when an object instance is open.
Now, I have a file field inside my model (which shows url and on click It opens a new window with that file).
I want to override it, instead of opening new window, I want to view the same inside an iFrame popup for supported file format (like doc, pdf) or else download the unsupported format on click. Also, highlight file field that ““file is unsupported, click to download””
Any help/guidance will be helpful.
EDIT: I am to do above task my own and I am able to show the image, and but iFrame part is not working.
class QuestionAdmin(admin.ModelAdmin): list_filter = ['group'] list_display = ['comment', 'supported_format'] readonly_fields = ['question_file', 'created_at'] class Meta: model = Question def question_file(self, obj): html = 'No File for the Question' filename = obj.question if filename: _name, ext = os.path.splitext(str(filename)) if ext in ['.jpg', '.png', '.jpeg', '.webp']: html = "<img src='%s'/>" % (obj.question.url) elif ext in ['.pdf', '.txt']: html = '<iframe src="%s"></iframe>' % ( obj.question.url) else: html = "<a href='%s' download>File Format Not supported, Click to Download</a>" % ( obj.question.url) return format_html( html )
Image of other File-
Error Image of iFrame-