3

Here is myapp.model

from django.db import models
from filer.fields.image import FilerImageField

class Item(models.Model):
    ...
    image = FilerImageField()
    ...

I'd like to hack in the middle of the django-filer uploading process and autocreate instances of Item for every image django-filer receives.

django-filer doesn't have traditional urls.py for me to just override single url pattern pointing to a custom view. How can I approach this?

EDIT:

Thanks to a hint from stefanfoulis, I eventually end up with this code:

from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from filer.fields.image import FilerImageField
from filer.models import Image

class Item(models.Model):
    ...
    image = FilerImageField()
    ...


@receiver(post_save, sender=Image)
def filer_signal(sender, instance, created, **kwargs):
    Item.objects.create(
        ...
        image=instance,
        ...).save()
    return
4

1 回答 1

2

django-filer 中的文件只是常规模型。FilerImageField 是 filer.models.Image 的 ForeignKey。因此,您可以收听 File 或 Image 模型的 post_save 信号并在那里创建您的实例。

信号文档:https ://docs.djangoproject.com/en/dev/ref/signals/#post-save

于 2013-07-27T17:11:51.760 回答