Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
johncarter-phntm opened this issue Nov 7, 2022 · 2 comments

Comments

@johncarter-phntm
Copy link

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.

@jams2
Copy link
Contributor

jams2 commented Nov 19, 2022

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

Potentially related: #57

@johncarter-phntm
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants