django项目的Apiqa用户存储后端
apiqa-storage的Python项目详细描述
apiqa存储
这个项目的目标是在minio上提供用户存储后端 所有apiqa django项目。在
豪图
- 将
apiqa-storage
添加到requirements.txt
。在
# Minio file storage
git+https://github.com/pik-software/apiqa-storage.git#egg=apiqa-storage
- 将
apiqa_storage
添加到设置文件中的INSTALLED_APPS
。在
- 将mixin
ModelWithAttachmentsMixin
添加到任何模型。进行并运行迁移。在
fromapiqa_storage.modelsimportModelWithAttachmentsMixinclassUserFile(ModelWithAttachmentsMixin,...):...
- 在开头添加序列化程序mixin并添加
attachments
,attachment_ids
到字段。在
fromapiqa_storage.serializersimportAttachmentsSerializerMixinclassModelWithAttachmentsSerializer(AttachmentsSerializerMixin,...):...classMeta:...fields=(...,'attachments','attachment_ids')
- 向urlpatterns添加下载和上传文件url。在
fromdjango.urlsimportpath,includeurlpatterns=[path('attachments/',include('apiqa_storage.urls')),]
- 或者将员工下载文件url添加到urlpatterns。在
fromdjango.urlsimportpath,includeurlpatterns=[# noqapath('attachments/',include('apiqa_storage.staff_urls')),]
- 添加清理文件任务到芹菜节拍配置。在
fromcelery.schedulesimportcrontabbeat_schedule={# apiqa-storage clean files'purge_attachments':{'task':'apiqa_storage.tasks.purge_attachments','schedule':crontab(hour=5)},}
- 添加所需的minio设置。在minio上创建bucket! django minio storage usage
MINIO_STORAGE_ENDPOINT='minio:9000'MINIO_STORAGE_ACCESS_KEY=...MINIO_STORAGE_SECRET_KEY=...MINIO_STORAGE_BUCKET_NAME='local-static'
- 在
其他设置
- MINIO_STORAGE_MAX_FILE_SIZE:上传的文件大小限制,人性化值。 见https://humanfriendly.readthedocs.io/en/latest/readme.html#a-note-about-size-units。默认100米
- MINIO_STORAGE_MAX_FILE_NAME_LEN:文件名长度限制。用于数据库字符限制。默认值100
- MINIO_STORAGE_MAX_FILES_COUNT:一个对象中的文件数限制。例如票据中有5个文件。无-是无限的。默认无
- MINIO_STORAGE_USE_HTTPS:使用HTTPS连接到MINIO。默认为False
- MINIO_STORAGE_CLEAN_PERIOD:删除N天后没有相关对象的文件。默认值30
- 在
运行测试
在
pip install -r requirements.txt pip install -r requirements.dev.txt docker-compose up pytest --cov .
- 项目
标签: