gtaylor/django-athumb

possible to use this without modelforms?

Closed this issue · 2 comments

I'm trying this out with the mongoengine backend, which does not use modelforms. wondering how, on image upload, to access the ImageWithThumbsFieldFile methods. I'm able to access the S3BotoStorage_AllPublic storage class, and get the image up to s3 calling _save on it:

if request.FILES.get('image'):
    file = request.FILES['image'] 
    doc.image.storage._save(file.name, file) #image is defined as a ImageWithThumbsField

thanks for the interesting project.

I'm fully open to packaging this up and making this possible through some convenience function/method/widget, so feel free to send a pull request with such a thing, but here is an example of how to do this without a modelform:

https://github.com/duointeractive/django-athumb/blob/master/athumb/management/commands/athumb_regen_field.py#L46

The basics of what's going on (in pseudocode):

  • open() and read() a file into fdat variable.
  • pass fdat as the parameter to the ContentFile init method.
  • someobj.img_field.save('filename.jpg', ContentField(fdat))

I hope this helps!

Thanks for your help.

I think my issue may even be a step back from this - if I attempt to call someobj.img_field.save(x,y) the following is raised:

'ImageWithThumbsField' object has no attribute 'save'