0

I'm making a website with django where you can basically upload a file to the django admin and download it whenever you need to view it. Very simple (making it for my dad which wants to organize his excel files for his work).

This is the problem, I hard coded the download path to the file I uploaded, which makes me have to modify the path every time I upload a new file with the same name (since django adds a random string of digits and characters every time you upload a file with the same name as before). What i'm currently doing is really inefficient, and would like to change that as soon as possible.

My idea is to make the FileField name editable in the django admin. I've come across this: list_editable = ['asd'].
I thought that might work and so I tried it. The results were interesting. I immediately saw a 'Save' button on the bottom of the admin site, which wasn't there before. But I still couldn't edit the FileField. I've searched this on multiple forums, the django documentation and more forums, only to not find anything useful.

This is a picture of how the admin page looks when I added the list_editable to my FileField.

So, I decided to look for an equivalent to see if that works. Again, I searched on multiple forums, but still found nothing.

Any type of answer or recommendation is very much appreciated.

Thanks in advance!!

alexholstv
  • 146
  • 1
  • 10
  • I think you need to update your model's upload_to: https://docs.djangoproject.com/en/3.0/ref/models/fields/#django.db.models.FileField.upload_to – munsu May 01 '20 at 03:00
  • I actually am using 'upload_to'. As far as I know, you only use it to save files to a specific folder. Maybe not? Let me go through the documentation on that. I will update you later – alexholstv May 01 '20 at 03:02
  • Im reading more on this `upload_to`, but it seems like you set it to what you want in the uploading process. I will need to be able to modify it myself since using the `upload_to` approach wont exactly work with my downloading process. Thanks tho! If you have any further recommendations, feel free to comment them. This is a weird situation here. – alexholstv May 01 '20 at 03:09
  • May I ask how you download the files? Is it directly accessing the folders of the server or through a view? – munsu May 01 '20 at 03:41
  • Directly hard coding a path. – alexholstv May 01 '20 at 03:49
  • I see. As an option you may want to consider, you can serve it through a view and at that point the uploaded name won't matter because you can just set the name before downloading. Something like this? https://stackoverflow.com/questions/9462999/how-to-download-a-filefield-file-in-django-view – munsu May 01 '20 at 03:54

0 Answers0