Например, я хочу иметь, скажем, 20 карточек, но внутри этих карточек количество PDF-файлов будет варьироваться от любого числа от 1 до 10. Мне это нужно, потому что благодаря этому PDF-файлы будет легко найти, и их будет очень удобно использовать.
Код: Выделить всё
class ArchitectPage(Page):
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 doc")],
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='+'
)
image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.CASCADE,
related_name='+'
)
caption = models.CharField(blank=True, max_length=250)
panels = [
ImageChooserPanel('image'),
FieldPanel('caption'),
DocumentChooserPanel('architect_pdf'),
]
Код: Выделить всё
{% for download in page.architect_pdf.all %}
{% image download.image fill-150x150-c100 %}
{% with doc=download.architect_pdf %}
{{ doc.title }}
{% endwith %}
{{ download.caption }}
{% with doc=download.architect_pdf %}
[url={{ doc.url }}]
[i][/i]
PDF
[/url]
{% endwith %}
{% endfor %}

Подробнее здесь: https://stackoverflow.com/questions/628 ... -orderable