wagtail-factories icon indicating copy to clipboard operation
wagtail-factories copied to clipboard

Feature Request: Add support for specifying a size to ListBlockFactory (like RelatedFactoryList)

Open johncarter-phntm opened this issue 2 years ago • 2 comments

It'd be really handy to have ListBlockFactory generate a list of N blocks, like RelatedFactoryList does, I think that's currently not possible unless we pass parameters to those sub-blocks.

johncarter-phntm avatar Nov 07 '22 20:11 johncarter-phntm

Hi @johncarter-phntm , could you give an example of how you would use this?

Potentially related: https://github.com/wagtail/wagtail-factories/issues/57

jams2 avatar Nov 19 '22 12:11 jams2

Hi, my use case is I want some blocks to be generated by the subfactory by default.

eg:

class MyBlockFactory(wagtail_factories.StructBlockFactory):
    items = wagtail_factories.ListBlockFactory(MyBlockItemFactory, size=3)

    class Meta:
        model = models.MyBlock

Also having support for lambda like RelatedFactoryList might be nice:

class MyBlockFactory(wagtail_factories.StructBlockFactory):
    items = wagtail_factories.ListBlockFactory(MyBlockItemFactory, size=lambda: random.randint(1, 5))

    class Meta:
        model = models.MyBlock

I'm thinking if individual elements were specified with items__0 etc this would still fill in up to size elements.

johncarter-phntm avatar Nov 20 '22 19:11 johncarter-phntm