On Fri, Feb 6, 2009 at 12:13 PM, Edgard Matos <edgardma...@gmail.com> wrote:
> My code: > > In model: > class User(db.Model): > user = db.UserProperty() > avatar = db.BlobProperty() > def __unicode__(self): > return self.email > > class UserForm(djangoforms.ModelForm): > class Meta(): > model = User > > > In view: > data = UserForm(request.POST, request.FILES) > if data.is_valid(): > user = users.get_current_user() > entity = data.save(commit=False) > entity.user = users.get_current_user() > entity.put() > > > But this error happen: > > 'NoneType' object has no attribute 'validate' > > > Somebody can help me? > What happened to the PIL error!? Did you solve that one or just remove some image-specific code? This error looks to be in the GAE code, see: http://www.mibgames.co.uk/2008/09/11/google-appengine-django-and-file-uploads/ Google search shows other reports of this, but no solutions that I can find in a brief scan. It seems that using a djangoforms.ModelForm for a GAE model that contains a BlobProperty might be somewhat broken. One way to get around it is to exclude the BlobProperty field from the djangoforms.ModelForm, replacing it with an explicit form FileField, and handle assigning the file data to the BlobProperty in your own code: from django import forms from google.appengine.ext.db import djangoforms class UserForm(djangoforms.ModelForm): avatar_file = forms.FileField() class Meta: model = User exclude = ['avatar'] def user(request): if request.method == 'POST': form = UserForm(request.POST, request.FILES) if form.is_valid(): user = users.get_current_user() entity = form.save(commit=False) entity.avatar = form.cleaned_data['avatar_file'].read() entity.user = users.get_current_user() entity.put() return HttpResponseRedirect('/') else: form = UserForm() return render_to_response('user.html', {'form': form }) Karen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---