wagtail / wagtail-factories

Factory boy classes for wagtail
http://wagtail-factories.readthedocs.io/en/latest/
MIT License
102 stars 40 forks source link

Support Streamfield with a nested StructBlock #23

Open easherma opened 4 years ago

easherma commented 4 years ago

Similar to https://github.com/mvantellingen/wagtail-factories/issues/12

I have a case like this:

StreamField(
        [
            ('section', StructBlock(
                [
                    ('section_heading_en', TextBlock(label='Heading [en]')),
                    ('pages', ListBlock(
                        PageChooserBlock(label="Page", page_type=[InformationPage, ServicePage]),
                        help_text='Select existing pages in the order you want them \
                        to display within each heading.\
                        Pages should be added only once to any single guide.')
                     ),
                ],
                label="Section"
            )),
        ],
        verbose_name='Add a section header and pages to each section',
        blank=True
    )

This is sorta puesdo code/bad formatting, but ideally I ought to be able to do something like:

    'section': wagtail_factories.StructBlockFactory({
        'section_heading_en': description = factory.Faker('text')
        'pages': ListBlockFactory({
            PageChooserBlockFactory
            })
        })
        }
    )
jams2 commented 2 years ago

Hi @easherma , to clarify: is your request to allow defining "anonymous" StructBlockFactories inline on a StreamFieldFactory declaration - i.e. not by subclassing StructBlockFactory separately?