Closed rochacbruno closed 11 years ago
What's your MongoEngine version?
I'm using 0.8.3 and it works as expected.
For me, value is <ImageGridFsProxy: 51ec3e32369e09121b94697f>
mongoengine==0.8.3
This example https://github.com/mrjoes/flask-admin/blob/master/examples/mongoengine/simple.py works for you? (Image model)
If yes, I need to figure out what's different.
Same error, maybe it is something in my env, Pillow or another lib.
Either there's difference between your MongoEngine version or I'm completely lost. I even reinstalled quokka with all dependencies into fresh virtualenv, added image field to Post model - it works as expected.
Value of the ImageField
is https://github.com/MongoEngine/mongoengine/blob/master/mongoengine/fields.py#L1252 and not _io.BytesIO
. And according to MongoEngine history, it was always like that. In your case, it is raw uploaded file data.
(quokka)serge@Cheetah ~/Work/quokka/quokka> python
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mongoengine
>>> mongoengine.get_version()
'0.8.3'
>>> import pymongo
>>> pymongo.version
'2.5.2'
Did you change Flask-Admin to keep existing form displayed after submission?
No, I did not changed anything in FlaskAdmin. My only customization on edit template is for wysiwyg editor (javascript).
Only thing I did is install Pillow instead of PIL. I will try in another v-env.
I just updated flask-admin and now it works! thanks again.
OK, here what was happening:
If that's your case (form validation), it solves the issue. If you didn't have any validation errors and you was seeing this issue - I still don't know what is causing it. Save
does not display form with uploaded data, it redirects user to other page. Save and add
creates new, empty form, without using request data.
I added checks to prevent this. Please update and try again. Make sure you see thumbnail when you edit model.
I installed Pillow
pip install Pillow
Defined my model
main_image = db.ImageField(thumbnail_size=(100, 100, True))
The upload controls appears in admin form but when I select a file and upload it the error is:
AttributeError: '_io.BytesIO' object has no attribute 'thumbnail'
value is
<FileStorage: u'crunchbang_linux_Wallpaper_uo6i6.jpg' ('image/jpeg')>