您好,我目前是 django/wagtail 的新手。我正在处理一个显示以前和当前工作/职位的关于页面。由于经验量不受限制,因此我已将位置流场阻塞。这是我的模型的代码。
#Create experience block
class ExperienceBlockStruct(StructBlock):
position_title = CharBlock(help_text="Enter a previous position title.")
description = CharBlock(help_text="Job description")
current_position = BooleanBlock(required=False, help_text="Check if
current position")
class Meta:
template = 'blocks/experience_block.html'
class ExperienceBlock(StreamBlock):
experience = ExperienceBlockStruct(icon="form")
这是我使用模型的页面
class About(Page):
profile_pic = "some image reduced code bc it currently works"
bio = RichTextField(blank=True)
resume = "some document reduced code bc it currently works"
experience = StreamField(ExperienceBlock())
content_panels = Page.content_panels + [
ImageChooserPanel('profile_pic'),
FieldPanel('bio'),
DocumentChooserPanel('resume'),
StreamFieldPanel('experience'),
]
现在我遇到的问题是如何渲染与current_position = True
不在不同区域的块。我试过了
templates/about.html
{% for block in page.experience %}
{% if block.current_position %}
{% include_block block %}
{% endif %}
{% endfor %}
但这并没有呈现任何东西。我也试过
<div class="experience">
{% if value.current_position %}
{{ value.position_title }}
{% else %}
{{ value.position_title }}
{% endif %}
</div>
但这会为每个块创建一个新的 div。我想要实现的是类似于blocks/experience_block.html
<div>
Current position(s): {% blocks with current_postion == True %}
</div>
<div>
Past position(s): {% blocks with current_postion == False %}
</div>
我怎样才能实现这样的目标?