Okay I just came up with this, let me know if this is a really hacky
way to do this. With this it will save the model, then the file and
then the model again, not sure how to do this since we don't get the
filename until after we save the file and we have to set the filename
in the database.

class PostSaveImageField(ImageField):
    def pre_save(self, model_instance, add):
        return Field.pre_save(self, model_instance, add)

    def post_save(self, sender, instance, created, **kwargs):
        file = getattr(instance, self.attname)
        if file and not file._committed:
            file.save(file.name, file, save=False)
            setattr(instance, self.attname, file)
            instance.save()

    def contribute_to_class(self, cls, name):
        post_save.connect(self.post_save, sender=cls)
        super(PostSaveImageField, self).contribute_to_class(cls, name)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to