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
lucemia
  • 6,349
  • 5
  • 42
  • 75
gwaramadze
  • 4,523
  • 5
  • 30
  • 42

1 Answers1

2

Files in django-filer are just regular models. FilerImageField is a ForeignKey to filer.models.Image under the hood. So you can listen to the post_save signal of the File or Image model and create your instance there.

Signal docs: https://docs.djangoproject.com/en/dev/ref/signals/#post-save

stefanfoulis
  • 649
  • 4
  • 16
  • Never used signals before, but I eventually figured it out, thanks! And, well, thanks for a great utility :] I am updating the question with my signal receiver for anyone looking for clues in the future. – gwaramadze Jul 27 '13 at 21:00