Django-filer: How to create folders and save uploaded images correctly?

2.4k Views Asked by At

The django-filer documentation makes no mention of how to correctly create folder and save the images savely inside.

My scenario: I have different users that can upload images through the frontend. Right now every FilerImage I create gets saved in the unspecified folder. How do I create a folder for every user programmatically?

And how do I move the uploaded FilerImage instance in code without violating the private/public settings of the file?

1

There are 1 best solutions below

0
On BEST ANSWER

Here is a solution I found out through fiddling around. It is very possible, that this is not the prgmatic way to handle this!

#Import Folder model
from filer.models.foldermodels import Folder

#Create Folder:
folder = Folder(owner=someuser, name="myname")  #owner is required
folder.save()

#Create Subfolder
subfolder = Folder(owner=someuser, name="subfolder", parent=folder)
subfolder.save()

More onfo can be gained by looking inside the Source-Code of the Folder Model, here.