views:

222

answers:

2

I have a model and form like so:

class Image(BaseModel):
  original = db.BlobProperty()

class ImageForm(ModelForm):
  class Meta:
    model = Image

I do the following in my view:

form = ImageForm(request.POST, request.FILES, instance=image)
if form.is_valid():

And I get:

AttributeError at /image/add/

'NoneType' object has no attribute 'validate'

Traced to:

/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/djangoforms.py in property_clean

  1. value: The value to validate. 606.
  2. Raises:
  3. forms.ValidationError if the value cannot be validated.
  4. """
  5. if value is not None:
  6. try:

  7. prop.validate(prop.make_value_from_form(value)) ...

  8. except (db.BadValueError, ValueError), e:

  9. raise forms.ValidationError(unicode(e)) 615. 616.
  10. class ModelFormOptions(object):
  11. """A simple class to hold internal options for a ModelForm class.

▼ Local vars

prop None

value InMemoryUploadedFile: Nearby.jpg (image/jpeg)

Any ideas how to get it to validate? It looks like FileField does not have a validate method, which Django expects...

A: 

The docs for the constructor say:

files: dict of file upload values; Django 0.97 or later only

Are you using Django 0.97? The bundled Django is 0.96, unless you explicitly select 1.0 or 1.1. Have you tried validating the form without the files parameter?

Nick Johnson
I'm explicitly setting 1.0.
pr1001
+2  A: 

It doesn't work with default django version. And bug is reported.

BTW, default installation raise other exeption. So possible problem with other part of your code.

Mikhail Kashkin
Thanks, Mikhail.
pr1001