0

I'm trying to construct the carousel model:

class Carousel(blocks.StructBlock):
    heading = blocks.CharBlock(required=False)
    carousel = blocks.ListBlock(
        blocks.StructBlock([
            ('slide', blocks.StreamBlock([
                ('image', ImageChooserBlock()),
                ('video', EmbedBlock())]),
             ),
            ('description', blocks.RichTextBlock()),
        ])
    )

Every slide consists of one image or video and a description.

I'm using StreamBlock in here because I couldn't find any other more suitable structural block type which would allow to the user to choose between image and video. Ideally I need something similar to the ChoiceBlock, except that the choices argument should expect other block types.

Is that feasible? Or at least is there a way to limit how many sub-blocks might be inserted from within the StreamBlock?

NarūnasK
  • 4,564
  • 8
  • 50
  • 76
  • Why not make the `carousel` ListBlock into a StreamBlock where the two options are 'image' (a StructBlock consisting of ImageChooserBlock + RichTextBlock) and 'video' (a StructBlock consisting of EmbedBlock + RichTextBlock)? – gasman Mar 13 '18 at 16:57
  • @gasman Thank you, it seems not too bad alternative. But in general, to solve the problem in the way I described it, do you think it's not feasible? – NarūnasK Mar 13 '18 at 17:56
  • 1
    There's no dedicated block type for choosing one block from a set. You can set `max_num=1` on StreamBlock, but the UI for that is a bit ugly... – gasman Mar 13 '18 at 18:00

0 Answers0