or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

admin.mdconfiguration.mdfields.mdindex.mdmodels.mdtemplate-utils.md
tile.json

tessl/pypi-django-filer

A file management application for Django that makes handling of files and images a breeze.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/django-filer@3.3.x

To install, run

npx @tessl/cli install tessl/pypi-django-filer@3.3.0

index.mddocs/

Django Filer

A 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.

Package Information

  • Package Name: django-filer
  • Language: Python
  • Installation: pip install django-filer
  • Django Version: Compatible with Django 3.2+
  • Python Version: Compatible with Python 3.8+

Core Imports

# Model imports
from filer.models import File, Folder, Image

# Field imports for use in your models
from filer.fields import FilerFileField, FilerImageField, FilerFolderField

Template tag imports:

{% load filer_tags %}
{% load filer_image_tags %}

Basic Usage

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 extension

Architecture

Django Filer uses a polymorphic model hierarchy for flexible file type handling:

  • File: Base polymorphic model for all file types with common fields and methods
  • BaseImage: Abstract base extending File with image-specific functionality
  • Image: Default concrete image model (swappable via FILER_IMAGE_MODEL setting)
  • Folder: Hierarchical folder model for organizing files with permission system
  • Permission System: Granular folder-level permissions (read, edit, add children)

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.

Capabilities

Core Models

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): ...

Core Models

Django Form Fields

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): ...

Form Fields

Configuration and Settings

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', ...]

Configuration

Admin Interface and Widgets

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): ...

Admin Interface

Template Tags and Utilities

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

Template Tags and Utilities