A file management application for Django that makes handling of files and images a breeze.
npx @tessl/cli install tessl/pypi-django-filer@3.3.0A comprehensive file and image management application for Django that provides advanced file handling capabilities through a user-friendly admin interface. Django Filer offers hierarchical folder organization, advanced file metadata management, polymorphic file models supporting various file types, integration with Django CMS, and thumbnail generation with customizable processors.
pip install django-filer# Model imports
from filer.models import File, Folder, Image
# Field imports for use in your models
from filer.fields import FilerFileField, FilerImageField, FilerFolderFieldTemplate tag imports:
{% load filer_tags %}
{% load filer_image_tags %}from django.db import models
from filer.fields import FilerFileField, FilerImageField
class Article(models.Model):
title = models.CharField(max_length=200)
content = models.TextField()
# File attachment
attachment = FilerFileField(
null=True,
blank=True,
related_name="article_attachments",
on_delete=models.SET_NULL
)
# Featured image
featured_image = FilerImageField(
null=True,
blank=True,
related_name="article_images",
on_delete=models.SET_NULL
)
# Working with files programmatically
from filer.models import File, Folder
from django.core.files.base import ContentFile
# Create a folder
folder = Folder.objects.create(name="My Documents")
# Upload a file
content = ContentFile(b"Hello, World!")
file_obj = File.objects.create(
file=content,
name="hello.txt",
folder=folder
)
# Access file properties
print(file_obj.url) # Public URL
print(file_obj.size) # File size in bytes
print(file_obj.extension) # File extensionDjango Filer uses a polymorphic model hierarchy for flexible file type handling:
The library integrates seamlessly with Django's admin interface, providing drag-and-drop upload, folder navigation, and file preview capabilities. It supports both public and private file storage through configurable storage backends.
Django Filer's polymorphic model system for files, folders, and images with full metadata support and admin integration.
class File(PolymorphicModel):
folder = models.ForeignKey(Folder, ...)
file = MultiStorageFileField(...)
name = models.CharField(max_length=255, ...)
owner = models.ForeignKey(settings.AUTH_USER_MODEL, ...)
is_public = models.BooleanField(...)
def has_read_permission(self, user): ...
def has_edit_permission(self, user): ...
@property
def url(self): ...
@property
def size(self): ...
class Folder(models.Model):
parent = models.ForeignKey('self', ...)
name = models.CharField(max_length=255, ...)
owner = models.ForeignKey(settings.AUTH_USER_MODEL, ...)
def has_read_permission(self, user): ...
def has_edit_permission(self, user): ...
def has_add_children_permission(self, user): ...
class Image(BaseImage):
date_taken = models.DateTimeField(...)
author = models.CharField(max_length=255, ...)
@property
def width(self): ...
@property
def height(self): ...Custom Django model fields for integrating filer objects into your models with admin widgets.
class FilerFileField(models.ForeignKey):
def __init__(self, **kwargs): ...
class FilerImageField(FilerFileField):
def __init__(self, **kwargs): ...
class FilerFolderField(models.ForeignKey):
def __init__(self, **kwargs): ...Comprehensive settings system for storage backends, permissions, validation, and admin interface customization.
# Core Settings
FILER_IMAGE_MODEL = 'filer.Image'
FILER_ENABLE_PERMISSIONS = True
FILER_IS_PUBLIC_DEFAULT = True
# Storage Configuration
FILER_STORAGES = {
'public': {...},
'private': {...}
}
# Upload Settings
FILER_UPLOADER_MAX_FILE_SIZE = 10 * 1024 * 1024 # 10MB
FILER_MIME_TYPE_WHITELIST = ['image/jpeg', 'image/png', ...]Rich Django admin integration with file browser, drag-and-drop uploads, and custom widgets for model fields.
class AdminFileWidget(ForeignKeyRawIdWidget):
def render(self, name, value, attrs=None, renderer=None): ...
class AdminImageWidget(AdminFileWidget): ...
class AdminFolderWidget(ForeignKeyRawIdWidget):
def render(self, name, value, attrs=None, renderer=None): ...Template tags for file handling, image processing, and utility functions for file operations.
# Template filters
{% load filer_tags %}
{{ file.size|filesize }}
{% load filer_image_tags %}
{{ image.width|divide_x_by:2 }}
# Utility functions
from filer.utils.files import handle_upload, get_valid_filename
from filer.validation import validate_upload