0

I have seen multiple replies for how to upload a file through Django ADMIN interface

There were two kind of replies:-

A) using django inline classes, as mentioned in link_A and link_B. I followed link_A But for some reason it did not work for me. So is there something missing in the above links mentioned?

I am not sure what is the purpose of following code block in the link_A:-

def save(self, *args, **kwargs): if not self.id: ... unzip your file ... ... encrypt your file if necessary ... super(File, self).save(*args, **kwargs)

Question:- Django admin shall automatically perform a SAVE functionality for you. So, what is the purpose of the above SAVE function when DJANGO ADMIN shall automatically do it for you?

B)using upload file functionality in normal DJango code(Not Django admin). I followed the link. It mentions to write a View that handles a POST request. And using a ModelForm save it and render the view again

What I did:- Added a FileField() button file = models.FileField(storage=fs).

My understanding:- Normal Django code(Not DJANGO Admin), we have to write ModelForms and VIEWS to handle HTTP respnose and request methods. But Django admin hides HTTP response and request functionality from the end user. Somehow it performs handling of HTTP request and HTTP response behind the scene. So me bypassing Django admin and trying to manually capture POST request(just for file upload) as mentioned in the link does not sound right.

From my point of view I just need to add a FileField() button to the DJANGO ADMIN. When i hit the SAVE button DJANGO ADMIN should handle POST request behind the scene as it does for normal model fields.

Question:- Is my understanding of how a file should be uploaded using Django ADMIN interface correct?

Community
  • 1
  • 1
user2166888
  • 579
  • 1
  • 5
  • 13
  • 1
    If your model has a `FileField` (or `ImageField`) you don't have anything special to do to upload a file from the admin (or from a ModelForm used in a view). What's your _real_ question ? – bruno desthuilliers Dec 04 '14 at 20:23
  • I need to **upload a zip file** from django admin. Save the uploaded **zip file** on the server and save the path(of the saved zip file) in database. Current scenario--> I have a Carnival model that gets registered with django Admin. It has a lot of fields like name ,place and upload zip folder button. So all the fields in the model should go in the database, and the uploaded zip folder button on the Django admin should upload a zip file to some predetermined path on the server and save the path in the database – user2166888 Dec 04 '14 at 21:00
  • 1
    So what's your problem exactly ??? If you have a `FileField` in your model, the default admin will automagically take care of all this, you don't have a single line of code to write to make it happen. – bruno desthuilliers Dec 05 '14 at 08:50
  • thanks it got resolved. thank you for your guidance – user2166888 Dec 09 '14 at 22:12
  • @brunodesthuilliers can you please have a look at the following question -> [link to question](http://stackoverflow.com/questions/27393130/django-admin-locating-hidden-model-forms-post-request-and-css) – user2166888 Dec 10 '14 at 04:24

0 Answers0