вот мой файл model.py
...
class LinkFields(models.Model):
link_external = models.URLField(
"External link",
blank=True,
null=True,
help_text='Set an external link if you want to describe the event from an other web site',
)
link_page = models.ForeignKey(
'wagtailcore.Page',
null=True,
on_delete=models.SET_NULL,
blank=True,
related_name='+',
help_text='Choose an existing page (event must have already been created)',
)
@property
def link(self):
if self.link_page:
return self.link_page.url
else:
return self.link_external
panels = [
FieldPanel('link_external'),
PageChooserPanel('link_page'),
]
class Meta:
abstract = True
class RelatedLink(LinkFields):
title = models.CharField(max_length=255, help_text="Link title")
panels = [
FieldPanel('title'),
MultiFieldPanel(LinkFields.panels, "Link"),
]
class Meta:
abstract = True
class HomePage(Page):
body = RichTextField(blank=True)
content_panels = Page.content_panels + [
FieldPanel('body', classname="full"),
InlinePanel('related_links', label="Related events"),
]
class EventsPage(Page):
# Database fields
date = models.DateField("Event date")
topicTag = models.CharField(max_length = 25)
name = models.CharField(max_length = 50)
city = models.CharField(max_length = 20, default="Where it is")
place = models.CharField(max_length = 20, blank=True)
body = RichTextField(blank=True)
# Search index configuration
search_fields = Page.search_fields + (
index.SearchField('topicTag'),
index.SearchField('place'),
index.FilterField('date'),
)
# Editor panels configuration
content_panels = Page.content_panels + [
FieldPanel('date'),
FieldPanel('topicTag'),
FieldPanel('name', classname="title"),
FieldPanel('city'),
FieldPanel('place'),
FieldPanel('body'),
]
class EventsRelatedLink(Orderable, RelatedLink):
page = ParentalKey('HomePage', related_name='related_links')
EventsPages — это подстраницы HomePage, которые сами отображают ссылки на последующие подстраницы. Моя проблема заключается в том, что для каждой ссылки подстраницы, которую я показываю на главной странице, я хотел бы получить доступ к свойствам так называемой подстраницы, чтобы отобразить своего рода предварительный просмотр.
Вот мой шаблон home_page.html:
{% extends "base.html" %}
{% load wagtailcore_tags %}
{% block body_class %}template-homepage{% endblock %}
{% block content %}
<h1>THE <span class="pink">OPEN SOURCE</span> INNOVATION SPRING</h1>
<div class="intro">{{ page.body|richtext }}</div>
{% if page.related_links.all %}
<ul>
{% for item in page.related_links.all %}
<li><a href="{{ item.link }}">{{ item.title }}</a></li>
<br><div class="description">{{ item.date }}
<span class="pink">[{{ item.topicTag }}]</span>
{{ item.name }} <span class="pink">[{{ item.city }}]</span>
</div>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
и, конечно, все "item.*" с * в качестве свойств модели EventsPage не работает. Я совершенно уверен, что ошибаюсь, но, пожалуйста, мне нужна помощь, чтобы сделать это.