3

I've just started using Django-Filer, and I'm a bit lost as to how I can actually reference the images uploaded in the admin system.

I need to display a simple dynamic gallery on a single page, that can handle multiple albums. Each album is a new heading on the page, and all the images in that album are displayed under that heading. The rough structure I'm hoping to use in Django-Filer's admin system is:

  • Root
    • Image Gallery
      • Album 1
        • Image 1
        • Image 2
        • Image 3
      • Album 2
    • Another Gallery

So my question is, using a loop in the Template, how would I go about displaying each image, using the Album folder as a new heading?

A second related question is: how would I go about extending the Folder model to include a description field, without breaking any of its functionality?

1 Answers1

1

It is what I did, maybe it'll be helpful with some adjustments (your first question).

First I create folders in filer (there can be subfolders inside).

After that I add new FoldersModel for each folder I want in the gallery. You will have to add "Image Gallery" and "Another Gallery" folders.

models.py

from filer.fields.folder import FilerFolderField

class FoldersModel(models.Model):
    folder = FilerFolderField()

views.py

from django.shortcuts import render
from models import FoldersModel

def show(request):
    all_folders = FoldersModel.objects.all()

    return render(request, 'main.html', {'all_folders': all_folders})

main.html

{% load thumbnail %}

    {% for f in all_folders %}

    <div class="title">{{ f.folder }}</div>

    {% for img in f.folder.files %}
    <!-- show files from folder -->
        <img src='{% thumbnail img 200x200 crop=scale %}'/>
    {% endfor %}

    {% for subfolder in f.folder.get_children %}
    <!-- getting all subfolders -->
        <div class="title">{{ subfolder }}</div>

        {% for img in subfolder.files %}
        <!-- show files from subfolder -->
        <img src='{% thumbnail img 200x200 crop=scale %}'/>
        {% endfor %}
    {% endfor %}

{% endfor %}

I'm not sure if this is the best way to do it but works for me.

Edit:
I think it is better to use this: https://django-filebrowser.readthedocs.io/en/latest/filelisting.html

Martinez
  • 115
  • 8