google app engine - More Blobstore upload woes with standard Django -


i'm implementing image upload feature django app (plain django 1.4 , not non-rel version) running on google app engine. uploaded image wrapped in django model allows user add attributes caption , search tags.

the upload performed creating blobstore upload url through function call blobstore.create_upload_url(url). function argument url bobstore redirects when upload complete. want url of default django form handler performs save/update of model wraps image don't have duplicate default django behaviour form validation, error reporting , database update.

i tried supplying reverse('admin:module_images_add') create_upload_url() doesn't work throws [errno 30] read-only file system exception. presume originates default django form handler again trying upload file standard django way hits brick wall of google app engine not allowing access file system.

at moment, way can see working without duplicating code strictly separating processes: 1 defining image model instance , second uploading actual image. not intuitive.

see this question , answer posted earlier.

any suggestions on how working using 1 form , reusing django default form handlers?

edit:

i've been reading on decorators (i'm relatively new python) , read, decorators appear able modify behaviour of existing python code. possible change runtime behaviour of existing form handler solve above using decorator? have (1) develop decorator , (2) attach default handler. i'm not sure if (2) possible has done runtime. cannot patch django code running on gae...

well, managed working. here's did in case runs well:

(1) removed imagefile attribute model. ended causing django try , file upload file system not allowed in gae.

(2) added blobstore key model key gae blobstore blob , required able serve image @ later stage. on side note: attribute has limited length using gae sdk considerably longer in gae production. ended defining textfield it.

(3) use storage.py daniel roseman's adaption this question , add blobstorefileuploadhandler file handlers in settings.py. ensure blobstore key there in request save model.

(4) created custom admin form contains imagefield named "image". required allows pick file. imagefield "virtual" purpose on form allow me pick file uploading. crucial per (1).

(5) overwrote render_change_form() method of modeladmin class prepare blobstore upload url. upload url has 2 versions: 1 adding new images , 1 saving changes existing. upload urls passed template via context object.

(6) modified change_form.html include blobstore upload url (5) form's action.

(7) overwrote save_model() method of modeladmin:

def save_model(self, request, obj, form, change):     if request.files.has_key("blobkey"):         blob_key = request.files["blobkey"].blobstore_info._blobinfo__key         obj.blobstore_key = blob_key     super(photofeatureadmin, self).save_model(request, obj, form, change) 

this allows me retrieve blob key set upload handler , set property of model.

for deletion of image models, added special function triggered delete signal of model. keep blobstore in sync image models in app.

that's it. above allows upload images blob store of gae each blob neatly wrapped in django model object admin users can maintain. thing there's no need duplicate standard django behaviour , model object of image can extended attributes in future.

final word: in opinion support blobs in plain django on gae poor considering above. should easier achieve this, without having rely on django non-rel code , rather long list of modifications; alternatively google should state in developer documents. unless missed something, undocumented territory.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -