I think this provides more (partially) detail: http://gulopine.gamemusic.org/2007/11/customizing-filenames-without-patching.html
Thomas On Dec 10, 2:01 pm, Julien <[EMAIL PROTECTED]> wrote: > I don't explicitly call it myself. > In fact, the _save_FIELD_file method (not save_avatar_file) is > automatically called when I save a UserProfile object in the admin > interface, or using a custom form generated by form_for_instance. > > Any idea? > > On Dec 10, 11:53 pm, Thomas <[EMAIL PROTECTED]> wrote: > > > I saw something similar with overridden save(). How/where do you call > > it? > > > Thomas > > > On Dec 10, 1:46 pm, Julien <[EMAIL PROTECTED]> wrote: > > > > 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 -~----------~----~----~----~------~----~------~--~---

