Created
January 29, 2021 15:23
-
-
Save nwjlyons/42ee33b1964b8be19604ac003c15f638 to your computer and use it in GitHub Desktop.
Determine what blocks are used in a Wagtail StreamField.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def block_types_used_in_field(queryset, field_name: str) -> set: | |
used_block_types = set() | |
for page in queryset: | |
for block in getattr(page, field_name): | |
used_block_types.add(block.block_type) | |
return used_block_types | |
# block_types_used_in_field(BlogPage.objects.all(), 'body') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment