11.Wagtail streams應用-2
建立標準塊
修改blocks模型,建立CardsBlock模型
from wagtail.core import blocks
from wagtail.images.blocks import ImageChooserBlock
class TitleBlock(blocks.StructBlock):
text = blocks.CharBlock(
required=True,
help_text="要顯示的文字",
verbose_name="文字"
)
class Meta:
template = "streams/title_block.html"
icon = "edit"
label = "標題"
help_text = "居中顯示在頁面上的文字"
class CardsBlock(blocks.StructBlock):
cards = blocks.ListBlock(
blocks.StructBlock(
[
("title", blocks.CharBlock(max_length=100, help_text="幫助文字", verbose_name="標題")),
("text", blocks.TextBlock(max_length=255, help_text="幫助文字", required=False, verbose_name="文字")),
("image", ImageChooserBlock(help_text="幫助文字"))
]
)
)
class Meta:
template = "streams/cards_block.html"
icon = "image"
label = "標準卡"
homo應用新增模型
from django.db import models
from wagtail.admin.edit_handlers import FieldPanel, PageChooserPanel, StreamFieldPanel
from wagtail.core.fields import StreamField
from wagtail.core.models import Page
from wagtail.images.edit_handlers import ImageChooserPanel
from streams import blocks
class HomePage(Page):
lead_text = models.CharField(
max_length=140,
blank=True,
help_text="橫幅標題下副文字",
verbose_name="引導文字")
button = models.ForeignKey(
"wagtailcore.Page",
blank=True, null=True,
related_name="+",
help_text="選擇要連線的頁面",
on_delete=models.SET_NULL,
verbose_name="按鈕")
button_text = models.CharField(
max_length=50,
default="閱讀更多",
blank=False,
help_text="按鈕文字",
verbose_name="按鈕文字")
banner_background_image = models.ForeignKey(
"wagtailimages.Image",
blank=False,
null=True,
related_name="+",
help_text="橫幅背景影像",
on_delete=models.SET_NULL)
body = StreamField([
("title", blocks.TitleBlock()),
("cards", blocks.CardsBlock()),
], null=True, blank=True, verbose_name="文字")
content_panels = Page.content_panels + [
FieldPanel("lead_text"),
PageChooserPanel("button"),
FieldPanel("button_text"),
ImageChooserPanel("banner_background_image"),
StreamFieldPanel("body")
]
cards_block.html
{% load wagtailimages_tags %}
{% for card in self.cards %}
{% image card.image fill-570x370 as img%}
<img src="{{ img.url }}" alt="{{ img.alt }}">
<h3>{{ card.title }}</h3>
{% if card.text %}
<p>{{ card.text }}</p>
{% endif %}
{% endfor %}
相關文章
- STREAMS筆記(2) 其他建立Streams的方式筆記
- 使用Java和Reactive Streams構建流式應用JavaReact
- Oracle Stream(2)--Streams功能Oracle
- akka-streams - 從應用角度學習:basic stream parts
- Amazon Kinesis Data Streams 實現跨賬戶應用日誌收集應用日誌
- 用dbms_streams_tablespace_adm來表空間的遷移(2)
- [翻譯] 響應式程式設計(Reactive Programming) - 流(Streams) - BLoC - 實際應用案例程式設計ReactBloC
- 8個實用的Java Streams APIJavaAPI
- oracle 10gR2中streams的配置[zt]Oracle 10g
- Oracle StreamsOracle
- java的應用2Java
- Yii2 應用概述
- 棧(2)--棧的應用
- db2diag應用DB2
- STREAMS MONITORING
- Kafka Streams 剖析Kafka
- streams 總結
- 並查集的應用2並查集
- Yii2 應用概覽
- 2 – 建立 Django 部落格應用Django
- ORACLE應用經驗(2)(轉)Oracle
- 精讀《web streams》Web
- Java 8 Streams filterJavaFilter
- Java 8 Streams map()Java
- Streams 流處理
- 用 VIPER 構建 iOS 應用架構(2)iOS應用架構
- Azkarra Streams簡介:Apache Kafka Streams的第一個微框架ApacheKafka框架
- 在Oracle11g Streams測試Streams資料傳輸Oracle
- cv2在影像上的應用-續2
- nodejs應用-PM2使用NodeJS
- Dart 2 Web 應用遷移指南DartWeb
- J2EE分散式應用分散式
- javascirpt div 移動應用2Java
- iptables基礎和應用(2)(轉)
- 2、安裝及管理應用程式
- STM32F103 高階應用(2)——中斷應用
- STREAMS筆記(1) step by step 建立一個Streams複製環境筆記
- Node.js Streams(流)Node.js