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

Support StructBlocks defined directly in the model #12

Open
mikemonteith opened this issue Aug 29, 2018 · 1 comment
Open

Support StructBlocks defined directly in the model #12

mikemonteith opened this issue Aug 29, 2018 · 1 comment

Comments

@mikemonteith
Copy link

A struct block doesn't necessarily always have it's own class definition.

From Wagtail's docs (http://docs.wagtail.io/en/v2.0/topics/streamfield.html#structblock):

('person', blocks.StructBlock([
    ('first_name', blocks.CharBlock()),
    ('surname', blocks.CharBlock()),
    ('photo', ImageChooserBlock(required=False)),
    ('biography', blocks.RichTextBlock()),
], icon='user'))

This is an alternate to defining a class:

class PersonBlock(blocks.StructBlock):
    first_name = blocks.CharBlock()
    surname = blocks.CharBlock()
    photo = ImageChooserBlock(required=False)
    biography = blocks.RichTextBlock()

    class Meta:
        icon = 'user'

At the moment, wagtail-factories only supports the class-based definition:

class MyTestPageFactory(wagtail_factories.PageFactory):

    body = wagtail_factories.StreamFieldFactory({
        'carousel': MyCarouselFactory
    })

    class Meta:
        model = models.MyTestPage

MyCarouselFactory has to be a subclass of wagtail_factories.StructBlockFactory, which depends on there being a class definition of the struct block.


Hopefully I will get time to look into this more. Has anyone come across this before, or have any ideas about how to solve it?

@easherma
Copy link

I've also run into this issue

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

No branches or pull requests

3 participants