I'm using django-filer on a project and have a model that looks like this:
from django.db import models
from filer.fields.folder import FilerFolderField
class Company(models.Model):
name = models.CharField(max_length=255)
logo = FilerFolderField()
For company/admin.py
, I'd like to override the logo
field so that I'm able to list the files in the folder. For example, in the shell, I can do this:
>>> from companies.models import Company
>>> c = Company.objects.get(pk=1)
>>> c.logo
<Folder: company a logos>
>>> c.logo.files
[<Image: logo-black.jpg>, <Image: logo-white.jpg>]
So, for example, when I edit a company object, I'd like to see an inline form with a logo in each field.
But I'm not sure how to do this in my CompanyAdmin
; I've looked at both formfield_for_foreignkey
and formfield_for_dbfield
, but it's not clear to me from either one how I would get the primary key of the model instance being edited so I can perform the lookup.