如果它对其他人有帮助,这就是我所做的。当用户浏览时,他们将被限制在包含查找图像的文件夹中,因为它们特定于报告的该部分。同样,上传图像会将其发送到同一文件夹。
简而言之,您必须:
- 将 CKEditor Uploader URL 指向您的视图版本
- 通过相应的表单视图更新 CKEditor Uploader 小部件
- 覆盖 CKEditor Uploader
ImageUploadView
和browse
视图以创建您想要的路径
例子
更新了 CKEditor URL 路径
path('myapp/<int:org_id>/report/<int:report_id>/finding/<int:finding_id>/image/upload', never_cache(ck_views.upload),
path('myapp/<int:org_id>/report/<int:report_id>/finding/<int:finding_id>/images', never_cache(ck_views.browse), name='ckeditor_browse'),
小部件更新
def get(self, request, *args, **kwargs):
context = {}
obj = self.get_object()
if obj is not None:
context['org'] = obj.report.org.id
form = FindingForm(instance=obj)
# Set image browse/upload path
image_kwargs = {
'finding_id': obj.id,
'org_id': obj.report.org.id,
'report_id': obj.report.id,
}
image_browse_path = reverse('ckeditor_browse', kwargs=image_kwargs)
image_upload_path = reverse('ckeditor_upload', kwargs=image_kwargs)
form.fields['description'].widget.config['filebrowserBrowseUrl'] = image_browse_path
form.fields['description'].widget.config['filebrowserUploadUrl'] = image_upload_path
context['form'] = form
return render(request, self.template_name, context)