如何使用django-storages在模型中存储和检索一个字段

我在工作中使用DRF构建面向客户的Web应用程序。我们有一个配置文件模型,其中包含一个ImageField,分别代表一个用户配置文件和他的配置文件图片。我的工作是停止使用FileSystem作为存储,并切换到使用s3存储图像。我认为我可以使用django-storages应用来做到这一点。但是我不明白如何让django-storages只能在模型中的一个字段上使用,而不是将其用作默认存储。我尝试使用FileField设置为storage的{​​{1}},但是无法将文件保存到s3。 总结我的问题-

  1. 如何将storages.backends.s3boto3.S3Boto3Storage配置为仅一个字段的存储空间
  2. 如何在模型中设置和检索字段。
django-storages
class Profile(models.Model):
    img = ImageField(upload_to=get_directory,default='img/generic_profile.jpg')
    name = CharField(max_length=256)
    new_s3_field = FileField(storage=S3Boto3Storage)
profile = Profile()
profile.new_s3_field = ContentFile('sample.jpg',open('sampel.jpg') # does not work
lms886 回答:如何使用django-storages在模型中存储和检索一个字段

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3169878.html

大家都在问