【问题标题】:how to integrate a django project to a cloud storage如何将 django 项目集成到云存储中
【发布时间】:2017-11-23 09:51:28
【问题描述】:

我有一个正在运行的 Django applicationwebfaction 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 中可行吗?

【问题讨论】:

    标签: python django cloud webfaction


    【解决方案1】:

    要查看详细信息,请参阅此 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 上,要获取保管箱访问令牌,请参阅此 link

    【讨论】:

    • 我在询问模型中要放置框的特定字段。不是整个数据库。所有其他字段都在 postgresql 中
    猜你喜欢
    • 2017-11-04
    • 2017-02-22
    • 2012-03-28
    • 2015-09-18
    • 2018-10-04
    • 2020-04-04
    • 2016-01-20
    • 2011-09-22
    • 2018-02-28
    相关资源
    最近更新 更多