0

I want to only .xlsm files to be uploadable to the form.I tried a lot of thing according to this question. But did not work. I don't know why? How can I solve it?

models.py

from django.core.validators import FileExtensionValidator
...
    pdf = models.FileField(upload_to=customer_directory_path, null=True, blank=True, validators=[FileExtensionValidator(allowed_extensions=['xlsm'])])

...

When I add this to my model :

def clean(self):
    pattern = re.compile('.*/.xlsm$')

    if not pattern.search(self.pdf):
        raise ValidationError(_('Only .xlsm files are accepted'))

I get an error:

expected string or bytes-like object

edche
  • 636
  • 6
  • 33

0 Answers0