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 = formset.save(commit=False)
for obj in instances:
# Always save IP address of changed objects
obj.ip_address = request.META["REMOTE_ADDR"]
obj.save()
formset.save_m2m()
admin.site.register(Shape, 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.