My question is not a duplicate of this question it is not related
Basically I got the following model where some uploaded documents will be public and some others private. To decide when the doc is private or not, when creating the instance, I set the field is_public=True/False
, then I will be able to choose the right direction within the AWS S3 bucket. So I want to be able to change the storage to PrivateMediaStorage()
when is_public=False
from my_project.storage_backends import PrivateMediaStorage
class Document(models.Model):
file = models.FileField(upload_to="uploaded_documents/%d-%m-%Y")
# file = models.FileField(upload_to="uploaded_documents/%d-%m-%Y",
# storage=PrivateMediaStorage())
uploaded_by = models.ForeignKey(UserProfile,blank=True,null=True)
nb_download = models.IntegerField(default=0)
is_public = models.BooleanField(default=False)
Here is the storage class in case it's important.
from storages.backends.s3boto3 import S3Boto3Storage
from django.conf import settings
class PrivateMediaStorage(S3Boto3Storage):
location = settings.AWS_PRIVATE_MEDIA_LOCATION
default_acl = 'private'
file_overwrite = False
custom_domain = False