Hi all,
I'm struggling to understand why, when I upload an image field (either
from the admin interface or from a custom view), the overriden
save_FOO_file method is never called.
In the following example, the "save_avatar_file" method is never
called. However the "_save_FIELD_file" method is called.
It looks a bit dirty to me, and I'd like to get rid of the
"_save_FIELD_file method", to only use a method for a given field (in
this case, "save_avatar_file").
Do you know why it's not working as expected?
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
avatar = models.ImageField(upload_to='/', null=True)
def _save_FIELD_file(self, field, filename, raw_contents, save):
if field.attname == 'avatar':
image = Image.open(StringIO.StringIO(raw_contents))
self.avatar = '%s.%s' % (self.user.id,
image.format.lower())
filename = settings.PROFILE_AVATAR_UPLOAD_DIR +
self.avatar
image.save(filename)
if save:
self.save()
def save_avatar_file(self, filename, raw_contents, save):
image = Image.open(StringIO.StringIO(raw_contents))
self.avatar = '%s.%s' % (self.user.id, image.format.lower())
filename = settings.PROFILE_AVATAR_UPLOAD_DIR + self.avatar
image.save(filename)
if save:
self.save()
Cheers,
Julien
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---