Ticket #6302: newforms-admin_filefield_initial_fix.diff

File newforms-admin_filefield_initial_fix.diff, 956 bytes (added by oyvind @…, 17 years ago)

Possible fix, not sure if this is the correct way to do this

  • django/newforms/fields.py

     
    433433        'missing': _(u"No file was submitted."),
    434434        'empty': _(u"The submitted file is empty."),
    435435    }
     436    _initial = None
    436437
    437438    def __init__(self, *args, **kwargs):
    438439        super(FileField, self).__init__(*args, **kwargs)
     
    451452            raise ValidationError(self.error_messages['empty'])
    452453        return f
    453454
     455    def _get_initial(self):
     456        return self._initial
     457
     458    def _set_initial(self, initial):
     459        self.required = False
     460        self._initial = initial
     461
     462    initial = property(_get_initial, _set_initial)
     463
    454464class ImageField(FileField):
    455465    default_error_messages = {
    456466        'invalid_image': _(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image."),
Back to Top