我在Django application
上正在运行webfaction server
。我想将我的django项目与云存储系统集成。我该如何整合呢?
以下是我的应用的详细信息:
它是django中的erp software
。它有一个名为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可以吗?
答案 0 :(得分:2)
要查看详细信息,请参阅此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()