On Tue, Oct 28, 2008 at 10:31 PM, varikin <[EMAIL PROTECTED]> wrote: > try: > object.photo._require_file() > except ValueError: > #handle exception
Wow, I never expected anybody to do something like that. :( > But I just don't know what this does or is suppose to. The way I read > it, if self is None, raise ValueError() which calls self.field.name > which would be invalid since self is None. Also, since calling this > method is done through a FieldFile object (or ImageFieldFile in this > case), it can't be None. Well, it can't be None, but it doesn't necessarily have a valid value. "if not self" doesn't actually check to see if it's None, but rather checks to see if the filename is blank. This can happen if you have a FileField that hasn't yet gotten a file attached to it, such a field with blank=True that never got a file in the admin or a new model instance created in a view that hasn't attached a file. The leading underscore means that it's meant to be a private method. It's there as a way to make Django's internal code simpler, so we didn't have to keep copying that ValueError message in a bunch of methods that all require a filename before they can proceed. That code you see is somebody checking to see if the field has a file attached to it or not. That's not really the best way to go about it though; this would be better: if not self: # handle "exception" -Gul --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---