Djangocms and django-filer: upload files into a specific folder

1.7k views Asked by At

I set up djangocms 3.1.0 with django-filer 0.9.11 and I created two custom djangocms plug-ins extending django-filer (as explained in documentation).

Everything works fine but now I need to set just for one of those plug-ins a specific folder in which I want to save uploaded file. At the moment files are saved using DEFAULT_FILER_STORAGES settings.

There is a way to set within a plug-in a specific storage folder?

1

There are 1 answers

0
tdsymonds On

Without seeing your code, I can't say for sure you're taking the same approach but let me explain how I've achieved uploads to a specific folder and perhaps you can make it work for yourself. Alternatively if you provide more details, I may be able to help more.

I have a script that creates a new filer image in a specified folder and links it to a model of mine. I've done this as follows:

from filer.models import Folder, Image

my_file = File(open(file_goes_here))
my_folder = Folder.objects.get_or_create(name='My Folder Name')[0]

filer_image = Image.objects.create(original_filename='My original file name', 
                                   file=my_file, 
                                   folder=my_folder)

new_image = MyModelImage(image=filer_image)
new_image.save()

I hope this helps?!