File upload after model save on Django admin?

As workaround, try generating UUID for file name (instead of using self. Id).

That's a solution but I think it's maybe easier to user the id for folder name. I will use your solution if I don't find my way. Thanks a lot!

– Sebastien Oct 3 at 13:58 This solution is good but it means that your upload folder is not very organized... – Sebastien Oct 7 at 12:45.

You will probably want to override the Model's save() method, and maybe come up with a custom "don't do anything" UploadHandler, then switch back to the original one and call save again. Https://docs.djangoproject. Com/en/dev/topics/http/file-uploads/ https://docs.djangoproject.Com/en/dev/topics/db/models/ What I would do in this situation however, is make a custom upload handler that saves the file off into some temp space.

Then I'd override the save method (in a mixin or something) that moves the file from temp to wherever you wanted it. @Tomek's answer is also another way. If you have your model generate it's own id, then you can use that.

A second to last suggestion which is what I do with my photo blog is instead of saving all the images in a directory like media/2/filename. Jpg I save the image by date uploaded.2011/10/2/image. Jpg This kind of helps any directory from getting too unwieldy.

Finally, you could hash the file names and store them in directories of hash name to kind of equally spread out the images in a directory. I've picked the date style because that's meaningful for me with that project. Perhaps there is another way you can name an image for saving that would mean something more than "model with id 2's pics" that you could use for this problem.

Good Luck!

1 for date based directory structure – Tomek Paczkowski Oct 3 at 14:45.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions