Django - Uploaded file type validation
===

I need to validate the uploaded file and should allow only '.pdf' and '.txt' files. Here is my model and and the form with validation function. But, I'm able to upload files even without the extension. I guess, the clean_content is not at all calling for validation. I want to know when it'll be called. In my view, I'm just saving the file from the `request.FILE`.

    class Section(models.Model):
    	content = models.FileField(upload_to="documents")

    class SectionForm(forms.ModelForm):
    	class Meta:
    		model = Section
        FILE_EXT_WHITELIST = ['pdf','txt']
    	
    	def clean_content(self):
    		content = self.cleaned_data['content']
    		if content:
    			file_type = content.content_type.split('/')[0]
    			print file_type
    			if len(content.name.split('.')) == 1:
    				raise forms.ValidationError("File type is not supported.")
    			if content.name.split('.')[-1] in self.FILE_EXT_WHITELIST:
    				return content
    			else:
    				raise forms.ValidationError("Only '.txt' and '.pdf' files are allowed.")