[Django]-Django Rest Framework does not show content from StreamField

4👍

You can customise the API output of a StreamField block by overriding the get_api_representation method. In this case, it might look something like:

class IngredientChooserBlock(ModelChooserBlock):
    def get_api_representation(self, value, context=None):
        if value:
            return {
                'id': value.id,
                'name': value.name,
                # any other relevant fields of your model...
            }

Then use IngredientChooserBlock('kitchen.Ingredient') in place of ModelChooserBlock('kitchen.Ingredient') in your StreamField definition.

👤gasman

Leave a comment