I have a few objects where I have no file attached.
I have this code:
if os.path.isfile(object.pdf_file.url):
object.url = object.pdf_file.url
else:
object.url = ""
But I am getting this error:
The 'pdf_file' attribute has no file associated with it.
This will throw the error because you need the file to get the url. I do not think that will work even if the file exists since isfile() needs a path, not the url which is relative to your webserver/django-settings for media url not where it is located on your server.
Try:
This will work since the FileField will return None if it is null.