From 0596a5dc5a3bdd0b79dc08213ca2e71aa8ba603b Mon Sep 17 00:00:00 2001 From: Azizbek <78961300+AzikDeveloper@users.noreply.github.com> Date: Sat, 9 Sep 2023 19:15:21 +0500 Subject: [PATCH] feat: save detected file type in validated file object So that it can be accessed in model's clean() method to do extra validation or just to save the type to another field. --- upload_validator/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/upload_validator/__init__.py b/upload_validator/__init__.py index 8e3923c..db8eb6a 100644 --- a/upload_validator/__init__.py +++ b/upload_validator/__init__.py @@ -55,7 +55,9 @@ def __call__(self, fileobj): # use detection details to transform it to proper mime if detected_type in ('application/octet-stream', 'application/vnd.ms-office'): detected_type = self._check_word_or_excel(fileobj, detected_type, extension) - + + fileobj._detected_type = detected_type + if detected_type not in self.allowed_mimes \ and detected_type.split('/')[0] not in self.allowed_mimes: raise ValidationError(