如何从wagtail下载文档文件?

2024-04-24 07:55:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经将pdf上传到了我的wagtail页面,但我不知道如何让它们可以从网页本身下载。这是我的models.py文件代码

我需要什么html代码来制作这些

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'),
   ]

Tags: thenametruesearchpdfonmodelspage
1条回答
网友
1楼 · 发布于 2024-04-24 07:55:58
<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>

相关问题 更多 >