Skip to content

v0.14 - StreamField callables

Compare
Choose a tag to compare
@zerolab zerolab released this 25 Mar 17:22
· 204 commits to main since this release

This release adds the much missed ability to use custom StreamField blocks callables or properties that is used aplenty with Page models.

class TextWithCallableBlock(blocks.StructBlock):
    text = blocks.CharBlock()

    graphql_fields = [
        GraphQLString("text"),
        GraphQLString("label"),
        GraphQLField("my_custom_field", source="get_custom_field"),
    ]

    @property
    def label(self):
        return "my block property"
    
    def get_custom_field(self, *args, **kwargs):
        return "welcome, callable source in StreamField"

This feature was developed by @kbayliss.