Use Case
I have a highly-reusable base form which I feed into a model form factory. Each model may have one or many FileFields. Each FileField will have different FileExtensionValidators. I would like to access the validators assigned to each FileField in order to extract the allowed_extensions so that I can use them to add {“accept”: “”} to the widget attrs for each file input on the form.
Note: This is just an attempt to improve the user experience. I’m not relying on this for security.
The Issue
I haven’t been able to figure out how to access the validators from any of the FileField objects. The validators are definitely working on the form, because files with invalid extensions raise validation errors as expected. But when I try to access the validators property from a FileField on an instantiated model, I get "AttributeError: ‘FieldFile’ has no attribute ‘validators’. And when I try to access the validators property from a FileField on the model class, I get "AttributeError: ‘FileDescriptor’ has no attribute ‘validators’.
The Question
Is there a way I can access the validator information for the validators assigned to a particular FileField? Or is there maybe a better way for me to try to achieve my goal?
Thanks in advance for any thoughts!