안녕하세요 저는 현재 django/wagtail을 처음 사용하고 있습니다. 나는 이전 및 현재 작업/위치를 보여주는 약 페이지에서 작업하고 있습니다. 나는 경험의 양이 제한되지 않았기 때문에 위치를 streamfield 블록으로 만들었습니다. 내 모델의 코드는 다음과 같습니다. 여기 booleanBlock이 True이면 렌더링 스트림 필드가 특정 방식으로 차단됩니다.
#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>
어떻게 이런 식으로 달성 할 수 있습니까?
은 첫 번째 템플릿 조각은 거의 정확했다