0

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.

3cheesewheel
  • 9,133
  • 9
  • 39
  • 59

1 Answers1

0

Try creating your own CompanyLogo form field subclassing the django-filer field. This answer will provide more information on how to do the reverse-foreign-key lookup.

Community
  • 1
  • 1
Christian Ternus
  • 8,406
  • 24
  • 39