I am trying to get upload_to of FileField to be an absolute path rather than relative to MEDIA_ROOT. If I make the path absolute I get a 400 error on post of file. If no leading / it stores under MEDIA_ROOT. The uploaded document needs to be held securely and not under MEDIA_ROOT but I also have images that need to go into MEDIA_ROOT so can't change it to be out public area.
This is my code...
class Document(models.Model): def get_upload_path(instance, filename): path = os.path.join( settings.DOCUMENT_DIR, str(instance.client.id), 'documents', str(instance.id), filename) return path uploaded = models.FileField(null=True, blank=True, upload_to=get_upload_path, max_length=255)