Skip to content

Instantly share code, notes, and snippets.

@christabor
Created May 9, 2014 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christabor/c94c527e1c7f7c41322a to your computer and use it in GitHub Desktop.
Save christabor/c94c527e1c7f7c41322a to your computer and use it in GitHub Desktop.
Clean django field with specified file type
def clean_data(self):
filetype = self.cleaned_data['data'].content_type
if not filetype == 'application/pdf':
raise forms.ValidationError(
'"{}" is not a valid file. Please upload a valid .PDF.')
else:
return self.cleaned_data['data']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment