您好,我目前對django/wagtail是新手。我正在研究顯示以前和當前工作/職位的關於頁面。由於經驗數量不受限制,我已經完成了位置流場塊。這是我的模型的代碼。如果booleanBlock爲True,則以某種方式渲染streamfield塊
#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>
我怎麼可能去實現這樣的事情?