I use django-cms for a project and in the frontend (template) I want to select a random image from a folder.
The media is managed by django-filer. I know how to use the files when I assign them directly in my models, but I can't figure out if and how it is possible to select a random image.
For a better understanding, I have a model where I can choose an image. If that is not set by the editor, I want to choose a random image as backup.
To solve this I had to use the Folder model of the filer. This is my model:
First I return the image of the model, if it is set. if not, I look for the specific folder and select a random image from that.
If nothing is found, I return
None
in any other case an image will be returned.My template looks like this: