After a lot of aggravating research and trial and error, this works
for me:
# Model
# FileFields are normally mapped to BlobProperty
class Image(db.Model):
image = db.BlobProperty()
# Form that has a proxy that will
# not be validated during ...is_valid()
class ImageForm(ModelForm):
image_proxy = forms.FileField()
class Meta:
model = Image
exclude = ['image']
# View that handles 'upload image' form
def image_new(request, **kwargs):
if request.method == 'POST':
form = ImageForm(request.POST, request.FILES)
if form.is_valid():
image = form.save(commit=False)
image.image = request.FILES['image_proxy'].read()
image.save()
return HttpResponseRedirect('/wherever')
else:
form = ImageForm(instance=image)
return render_to_response('image_edit.html', [{'form': form}])
# View that handles requests for JPG images
def get_jpg(request, image_id):
image = Image.get_object(id=image_id)
return HttpResponse(image.image, mimetype='image/jpg')
Upload image form template snippet:
<form method="POST" action="" enctype="multipart/form-data">
<table>{{ form }}</table>
<input type="submit" value="upload"/>
</form>
Hopefully I didn't leave anything out - I tried just to show the
relevant code from my more complicated app. I hope this helps. Please
let me know if you still have trouble.
The whole appengine/django marrriage is a little funky. It makes it
hard to back port your project to a straight Django/MySQL environment.
On Jul 29, 5:00 am, Riverside <
webpo...@gmail.com> wrote:
> I think it is a bug. When I have upgraded sdk to the newest version, I
...>