You could do something like this - perhaps in a validators.py
:
from django.core.exceptions import ValidationError
def validate_file_size(value):
filesize = value.size
if filesize > 10485760: # 10 MiB in bytes
raise ValidationError("The maximum file size that can be uploaded is 10 MiB")
else:
return value
and then in your models.py
:
from .validators import validate_file_size
file = models.FileField(..., validators=[validate_file_size])
However, this is server side, not client side. Therefore, each submission of the file transmits the file over the wire to you, resulting in bandwidth charges. If someone was to upload a 1 GiB file, then the upload would consume 1 GiB of bandwith, even if it is rejected by the server.
Client-side validation would require some JS like this, but you would also need server-side validation.