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.

4

1 回答 1

0

尝试创建您自己的 CompanyLogo 表单字段,子类化 django-filer 字段。这个答案将提供有关如何进行反向外键查找的更多信息。

于 2013-10-04T22:01:24.277 回答