WeGi February 2016

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

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?

Answers


WeGi February 2016

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.

Post Status

Asked in February 2016
Viewed 3,913 times
Voted 8
Answered 1 times

Search




Leave an answer