Add usage examples for EmailBlock, IntegerBlock, DecimalBlock

Thanks to @OktayAltay for the original pull request.
pull/2753/merge
Matt Westcott 2016-08-08 20:15:45 +01:00
rodzic fcea4ee30d
commit bc7739e104
1 zmienionych plików z 27 dodań i 0 usunięć

Wyświetl plik

@ -96,6 +96,8 @@ EmailBlock
A single-line email input that validates that the email is a valid Email Address. The keyword arguments ``required`` and ``help_text`` are accepted.
For an example of ``EmailBlock`` in use, see :ref:`streamfield_personblock_example`
IntegerBlock
~~~~~~~~~~~~
@ -103,6 +105,8 @@ IntegerBlock
A single-line integer input that validates that the integer is a valid whole number. The keyword arguments ``required``, ``max_length``, ``min_length`` and ``help_text`` are accepted.
For an example of ``IntegerBlock`` in use, see :ref:`streamfield_personblock_example`
FloatBlock
~~~~~~~~~~
@ -117,6 +121,8 @@ DecimalBlock
A single-line decimal input that validates that the value is a valid decimal number. The keyword arguments ``required``, ``max_value``, ``min_value``, ``max_digits`` and ``decimal_places`` are accepted.
For an example of ``DecimalBlock`` in use, see :ref:`streamfield_personblock_example`
RegexBlock
~~~~~~~~~~
@ -388,6 +394,27 @@ Since ``StreamField`` accepts an instance of ``StreamBlock`` as a parameter, in
carousel = StreamField(CarouselBlock())
.. _streamfield_personblock_example:
Example: ``PersonBlock``
------------------------
This example demonstrates how the basic block types introduced above can be combined into a more complex block type based on ``StructBlock``:
.. code-block:: python
from wagtail.wagtailcore import blocks
class PersonBlock(blocks.StructBlock):
name = blocks.CharBlock()
height = blocks.DecimalBlock()
age = blocks.IntegerBlock()
email = blocks.EmailBlock()
class Meta:
template = 'blocks/person_block.html'
.. _streamfield_template_rendering:
Template rendering