The website I was working on involves uploading of some files and downloading them. But I have to display the path where an uploaded file is stored. So a model FileField named 'bulk_add' is added in models.py to store filepath like this:
bulk_add = models.FileField(upload_to=assignment_bulk_upload_path, null=True)
So when user has uploaded a file, I have to display the path where the file is stored in my website like this:
But as FileField by default will allow max_length = 100, whenever the user uploads a file with very long name, the entire length of filepath crosses the default maxlength(since filepath involves filename) and error page is shown.
So I want to write a python function to get the number of characters in filepath when a file is uploaded and display error "File name is long" when the filepath length crossses 100. So how to get no of characters in filepath in the FileFIeld?
Is there a function like length()
so that I'll get the no. of chars in filepath when I do bulk_add.length()
?