首页 > 解决方案 > How overwrite Django Admin readonly FileFields HREF url

问题描述

I have a Django project in production on Apache and I've made a model with file that is uploaded to custom path. Now I need to change it's representation in Django admin details. My FileField in admin is readonly and I want that it only shows a correct link to open the file in a new tab.

The problem is that I have alias in Apache and the current link showed in the admin is for example:

/var/www/html/moeaforhdl/moeaforhdlweb/uploads/uploaded_c_files/194/extracted_dfg.json 

Screenshot:

enter image description here

But when I click to open the file it tries to open this URL:

http://201.174.122.25/moeaforhdlweb/uploads/var/www/html/moeaforhdl/moeaforhdlweb/uploads/uploaded_c_files/194/extracted_dfg.json

when the correct URL to open the file is:

http://201.174.122.25/moeaforhdlweb/uploads/uploaded_c_files/194/extracted_dfg.json

I need to remove this part when users click on the link in admin forms and details:

/var/www/html/moeaforhdl/moeaforhdlweb/uploads

How can I overwrite this URL in admin panel, por example in admin.py? Thank you so much.

标签: pythondjangoadmin

解决方案


推荐阅读