gpt4 book ai didi

python - 如何将 django 项目集成到云存储

转载 作者:行者123 更新时间:2023-12-01 02:25:30 24 4
gpt4 key购买 nike

我有一个在 webfaction 服务器 上运行的 Django 应用程序。我想将我的 django 项目与云存储系统集成。我如何整合它?

这是有关我的应用程序的详细信息:它是 django 中的erp 软件。它有一个名为 Projects 的应用程序。在该应用程序中,它有一个 model 名称 Project

  class Project(BaseModel):
event = models.ForeignKey("events.Event")
client = models.ForeignKey("clients.Client")
project_supervisor = models.ForeignKey("staffs.Staff", blank=True, null=True)
name = models.CharField(max_length=128)
project_number = models.CharField(max_length=128, unique=True)
currency = models.ForeignKey("projects.Currency")
hall_number = models.CharField(max_length=128)
stand_number = models.CharField(max_length=128)
start_date = models.DateField()
end_date = models.DateField()
notes = models.TextField(blank=True, null=True)
terms_and_conditions = models.TextField(blank=True, null=True)
is_design_required = models.BooleanField(choices=BOOL_CHOICES, default=False)
status = models.CharField(max_length=128, choices=PROJECT_STATUS, default="pending")
admin_confirmed = models.BooleanField(default=False)
is_quote_send = models.BooleanField(default=False)
is_estimate_send = models.BooleanField(default=False)
is_deleted = models.BooleanField(default=False)

我想向这个模型添加一个额外的字段来存储项目详细信息。我想将这些图片上传到云端,比如 dropbox 或 google ,并想通过 django 上传。这意味着我想存储该文档字段仅存在于云数据库中?这在 DJANGO 中可能吗?

最佳答案

要查看详细信息,请参阅此 stackoverflow Question
APP v2 在 dropbox 上上传文件的源代码是。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import dropbox

class TransferData:
def __init__(self, access_token):
self.access_token = access_token

def upload_file(self, file_from, file_to):
"""upload a file to Dropbox using API v2
"""
dbx = dropbox.Dropbox(self.access_token)

with open(file_from, 'rb') as f:
dbx.files_upload(f.read(), file_to)

def main():
access_token = '******'
transferData = TransferData(access_token)

file_from = 'test.txt'
file_to = '/test_dropbox/test.txt' # The full path to upload the file to, including the file name

# API v2
transferData.upload_file(file_from, file_to)

if __name__ == '__main__':
main()

源代码托管在 GitHub code link要获取 Dropbox 访问 token ,请参阅此 link

关于python - 如何将 django 项目集成到云存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47452395/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com