4

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?

WeGi
  • 1,908
  • 1
  • 21
  • 33
  • Creating directories with django requires the type of access to the file system that is probably better to avoid. To customize what django does with the files you have the file_complete event, which you can use in a custom upload handler https://docs.djangoproject.com/en/1.9/ref/files/uploads/#custom-upload-handlers – Aviah Laor Feb 08 '16 at 12:40
  • In case anyone else was confused by Aviah's comment: django-filer's virtual "folders" are not the same as Django creating directories on the filesystem. – tehfink Oct 16 '18 at 09:06

1 Answers1

1

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.

WeGi
  • 1,908
  • 1
  • 21
  • 33