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 %}
相關文章
- 使用Java和Reactive Streams構建流式應用JavaReact
- akka-streams - 從應用角度學習:basic stream parts
- Amazon Kinesis Data Streams 實現跨賬戶應用日誌收集應用日誌
- [翻譯] 響應式程式設計(Reactive Programming) - 流(Streams) - BLoC - 實際應用案例程式設計ReactBloC
- 8個實用的Java Streams APIJavaAPI
- 應用題2
- STREAMS MONITORING
- java的應用2Java
- Yii2 應用概述
- Streams 流處理
- 精讀《web streams》Web
- Azkarra Streams簡介:Apache Kafka Streams的第一個微框架ApacheKafka框架
- 2 – 建立 Django 部落格應用Django
- nodejs應用-PM2使用NodeJS
- Yii2 應用概覽
- 並查集的應用2並查集
- Flutter Provider and Streams [翻譯]FlutterIDE
- 流和向量(Streams and Vectors)
- Java Streams 的潛力Java
- Node.js Streams(流)Node.js
- STM32F103 高階應用(2)——中斷應用
- cv2在影像上的應用-續2
- Kafka ETL 的應用及架構解析|告別 Kafka Streams,讓輕量級流處理更加簡單Kafka架構
- 2、安裝及管理應用程式
- Dart 2 Web 應用遷移指南DartWeb
- 聊聊rocketmq-streams的ILeaseServiceMQ
- Python應用【PDF處理-pypdf2】Python
- 2、Node.js 第一個應用Node.js
- booststrap select2的應用總結
- 使用 HTTP/2 加速 Node.js 應用HTTPNode.js
- 攻擊JavaWeb應用[9]-Server篇[2]JavaWebServer
- Exhibeo 2 for Mac(網路相簿應用程式)Mac
- asyncio非同步IO——Streams詳解非同步
- Kafka Streams開發入門(1)Kafka
- java .stream(). 使用介紹 Streams APIJavaAPI
- How to Use the Stdin, Stderr, and Stdout Streams in Bash
- Python 基礎 2-2 列表的實際應用場景Python
- OS課 Level 2 實驗(2):軟體的部署與應用