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?