Table Of Contents

Previous topic

Basic usage

Next topic

Override default templates

This Page

Admin interface

As you probably know, Django comes with a nice admin interface. The django-files app comes with two pre-configured classes for using in the admin interface; A ModelAdmin class for the Attachment model, and a pretty basic GenericStackedInline class you can use to hook into your models which has files attached.



By enabling the admin autodiscover feature, this should automatically appear in your admin site.



This generic inline can be used to get a nice list of attachments related to some object. Take our Shape model from previous examples.

from django.contrib import admin
from demosite.models import Shape
from files.admin import AttachmentInlines

class ShapeAdmin(admin.ModelAdmin):
    inlines = [AttachmentInlines]

    def save_formset(self, request, form, formset, change):
        instances =
        for obj in instances:
            # Always save IP address of changed objects
            obj.ip_address = request.META["REMOTE_ADDR"]
        formset.save_m2m(), ShapeAdmin)


The user in question needs to be a staff member to be able to log into the admin interface.

In addition, the following conditions must be met.

  • Add a new attachment
    • The loggin in user needs to have the files.add_attachment permission.
  • Delete
    • The logged in user needs to have superuser status.
  • Change
    • The loggine in user needs to have files.change_attachment permission.