Skip to content

Instantly share code, notes, and snippets.

@nwjlyons
Created January 29, 2021 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nwjlyons/42ee33b1964b8be19604ac003c15f638 to your computer and use it in GitHub Desktop.
Save nwjlyons/42ee33b1964b8be19604ac003c15f638 to your computer and use it in GitHub Desktop.
Determine what blocks are used in a Wagtail StreamField.
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