python - How to make the document files downloadable from wagtail?
问题描述
I have uploaded pdf's to my wagtail page but I cant work out how to get them to actually be downloadable from the web page itself. This is my code for the models.py file.
What html code do I need to make these?
class ArchitectPage(Page):
pdf_files = models.ForeignKey(
'wagtaildocs.Document',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
search_fields = Page.search_fields + [
] # these are if adding a search to the website
# content tab panels
content_panels = Page.content_panels + [
MultiFieldPanel(
[InlinePanel('architect_pdf', max_num=20, min_num=0, label="architect pdf")],
heading="architect pdf"
),
]
# what to call the panels on wagtail
edit_handler = TabbedInterface([
ObjectList(content_panels, heading='Content'),
ObjectList(Page.promote_panels, heading='SEO'),
ObjectList(Page.settings_panels, heading='Settings', classname='settings'),
# classname settings adds the cog
])
class ArchitectDownloads(Orderable):
page = ParentalKey(ArchitectPage, on_delete=models.CASCADE, related_name='architect_pdf')
architect_pdf = models.ForeignKey(
'wagtaildocs.Document',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
panels = [
DocumentChooserPanel('architect_pdf'),
]
解决方案
<ul>
{% for download in page.architect_pdf.all %} {# loop over the ArchitectDownload objects #}
{% with doc=download.architect_pdf %} {# retrieve the Document object for each one #}
<li><a href="{{ doc.url }}">{{ doc.title }}</a></li>
{% endwith %}
{% endfor %}
</ul>
推荐阅读
- python - 如何将 csv 文件批量加载到 DStreams 中?
- ios - 如何解码对象数组并从 userdefaults 中检索它?
- oracle - SELECT FOR UPDATE 似乎不适用于 Oracle 12.1/19.3 的 PL/SQL 驱动的测试用例
- android - 如何在 Mesibo 中更改调用片段的标题和图像
- azure-devops - 提取文件:处理“未找到文件”警告
- typescript - 我可以关闭用于在 lambdas 中解构的 eslint tyfedef 规则吗
- sql-server - 在原始帖子之后插入潜在回复时按日期对记录进行排序
- javascript - 只能从枚举数组中获取值的 JSDoc 文档参数
- google-chrome - 谷歌翻译在 Chrome 中显示空白屏幕
- python-3.x - python中更好的曲线拟合