Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

saved_file signal only fired in Django admin #185

Closed
vinta opened this issue Dec 26, 2012 · 3 comments
Closed

saved_file signal only fired in Django admin #185

vinta opened this issue Dec 26, 2012 · 3 comments

Comments

@vinta
Copy link

vinta commented Dec 26, 2012

in models.py

from django.db import models

from easy_thumbnails.fields import ThumbnailerImageField
from easy_thumbnails.signals import saved_file

class Album(models.Model):
    artist = models.ForeignKey(Artist, related_name='albums')
    name = models.CharField(max_length=255)
    cover = ThumbnailerImageField(upload_to='album/%Y/%m/%d')

    class Meta:
        ordering = ('-id',)

    def __unicode__(self):
        return self.name


@receiver(saved_file)
def post_save_cover(sender, fieldfile, **kwargs):
    print('saved_file')

in views.py

import os

from django.core.files import File

a1 = Album.objects.get(id=1)
file_path = '/home/gibuloto/test.jpg'
file_name = os.path.basename(file_path)
a1.cover.save(file_name, File(open(file_name, 'rb')))

This saved_file only fired when I save a image to cover field in Django admin.

I use version 1.1

@SmileyChris
Copy link
Owner

I'm not following the problem. What is an example of behavior that is not working as expected?

@vinta
Copy link
Author

vinta commented Dec 26, 2012

After the line a1.cover.save(file_name, File(open(file_name, 'rb'))), the saved_file signal should be fired, right?
But it didn't.

Or I did something wrong?

@SmileyChris
Copy link
Owner

Ah - the saved_file signal fires when an uncommitted file is attached to the model and it is then the model is saved. If you're directly modifying the underlying file with save (which commits the file before saving the model), you'll need to fire the signal yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants