Whoops I pressed send too soon. In your forms code create a method called clean_imageForm and add your custom error code there.
On Wed, Aug 27, 2008 at 1:33 PM, James Matthews <[EMAIL PROTECTED]> wrote: > In your forum code you can add the clean_imageForm and add your cleaning > code in there. > > On Wed, Aug 27, 2008 at 11:39 AM, Rajesh Dhawan <[EMAIL PROTECTED]> > wrote: > > > > Hi, > > > >> I have an image upload form and I want to INvalidate the form if the > >> uploaded image it too big. How can I get an error message in the form > >> saying the uploaded image is too big? > >> > >> ===Model================== > >> class Image(models.Model): > >> image = models.ImageField(upload_to='imageupload') > >> > >> ===View=================== > >> if imageForm.is_valid(): > >> inst = imageForm.save(commit=False) > >> if inst.image.width > 640: > >> #TODO: set the error message of this form to 'image is too > >> big' > > > > It's much simpler (and more appropriate) to do this in your form > > itself. Specifically, add a clean_image method to your form and check > > the image dimensions there. Then raise a forms.ValidationError on the > > appropriate condition. Something along these lines would be a start: > > > > def clean_image(self): > > from django.core.files.images import get_image_dimensions > > image = self.cleaned_data['image'] > > w, h = get_image_dimensions(image) > > if w > 640: > > raise forms.ValidationError(u'That image is too wide.') > > return image > > > > -Rajesh D > > > > > > > > > > -- > http://www.goldwatches.com/ > > -- http://www.goldwatches.com/ --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---