thanks karen..guess I'm overworked -- I was trying out something like "if self.cleaned_data['avatar'] == ' ' " ....failed to notice that the ImageField is 'None' if empty...
thanks a bunch..you made my day :-) -pd. On Mar 26, 10:07 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On Wed, Mar 26, 2008 at 5:15 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > I'm using an avatar imagefiled in the model and have defined an > > imagefield in the registration form I'm using for the user to sign up. > > avatar is not a required field (both in the form as well as in the > > model) > > > I've got validation included in the Registration Form for the uploaded > > image size: > > > def clean_avatar(self): > > > size = len(self.cleaned_data['avatar'].content) > > if size > 500 * 1024: > > raise forms.ValidationError('Size exceeded allowable > > limit') > > > return self.cleaned_data['avatar'] > > > All works well if the user does upload an image. If no image is > > uploaded, I get a > > "NoneType' object has no attribute 'content' " exception. > > > Which I understand why -- because no file has been uploaded and so > > there is no content attribute present. > > > however, I'm not sure how I can first check if a file has been > > uploaded by user or not..and then have the above clean method be > > invoked only when a file has been uploaded...if not, skip validating > > the input. > > > any ideas ? > > I don't believe you can bypass your clean method in the case where no file > was uploaded. Rather you should change your clean_avatar function to handle > the case of no file being uploaded. That is, only do the size check if > self.cleaned_data['avatar'] is not None. > > 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---