My requirement is ,user uploaded image has to be saved in Database after a custom validation for size and has to display to user. In models.py class Marketplace(models.Model): title_name=models.CharField(max_length=125) photo1 = models.ImageField(upload_to= 'img/marketplace/%Y/%m/ %d', null=True, blank=True) photo2 = models.ImageField(upload_to = 'img/marketplace/%Y/%m/ %d', null=True, blank=True)
In forms.py class MarketplaceForm(forms.Form): title_name = forms.CharField(max_length=125) photo1 = forms.ImageField(required=False) photo2 = forms.ImageField(required=False) def clean_photo1(self): from django.core.files.images import get_image_dimensions logo = self.cleaned_data['photo1'] w, h = get_image_dimensions(logo) if w > 150 or h > 150: raise forms.ValidationError(u'That logo is too big. Please resize it so that it is 32x32 pixels or less, although 150x150 pixels is optimal for display purposes.') return self.cleaned_data['photo1'] def save(self): new_market = Marketplace.objects.create (title_name=self.cleaned_data['title_name'], photo1=self.cleaned_data['photo1'], photo2=self.cleaned_data['photo2'], return new_market In views.py def postyour_adds(request): if request.method=='POST': form=MarketplaceForm(request.POST) if form.is_valid(): newmarket=form.save() return HttpResponseRedirect("/ thanksfor_post/") else: form = MarketplaceForm() return render_to_response("marketplace/ postyour_add.html", {'form': form}) In postyour_add.html {% block content %} <h3> Enter your choice</h3> <form action="" method="post" enctype="multipart/form-data"> {{ form.as_p }} <input type="submit" value="Create the account"> </form> {% endblock %} The Error i am getting says photo1 and photo2 are None Exception Type: TypeError Exception Value: coercing to Unicode: need string or buffer, NoneType found Local vars shows no values is assigned to photo1 and photo2 Any solution please Gjango --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---