Created
September 26, 2011 12:46
-
-
Save gileno/1242148 to your computer and use it in GitHub Desktop.
File Size verification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.template.defaultfilters import filesizeformat | |
def clean_file(self): | |
if self.cleaned_data['file']: | |
size = self.cleaned_data['file'].size | |
max_size = settings.MAX_GROUP_FILE_SIZE | |
if size > max_size: | |
raise forms.ValidationError(_(u'O tamanho máximo do arquivo deve ser de %s') % filesizeformat(max_size)) | |
return self.cleaned_data['file'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Desculpe a minha ignorância, e vejo também que já faz tempo que foi postado o código, mas preciso que me diga como utilizo esta função, como faço pra ela validar e verificar realmente o tamanho do arquivo que se está sendo upado atende ao limite?
No aguardo, abraços.