Как сделать файлы документов загружаемыми из трясогузки? - PullRequest
1 голос
/ 05 марта 2020

Я загрузил PDF-файлы на свою страницу трясогузки, но не могу понять, как заставить их действительно загружаться с самой веб-страницы. Это мой код для файла 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'),
   ]

1 Ответ

2 голосов
/ 05 марта 2020
<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>
...