Jelajahi Sumber

Add custom get_api_representation for EmbedBlock

Sage Abdullah 4 bulan lalu
induk
melakukan
16f248c4dd
1 mengubah file dengan 6 tambahan dan 1 penghapusan
  1. 6 1
      bakerydemo/base/blocks.py

+ 6 - 1
bakerydemo/base/blocks.py

@@ -102,6 +102,11 @@ class BlockQuote(StructBlock):
         description = "A quote with an optional attribution"
 
 
+class CustomEmbedBlock(EmbedBlock):
+    def get_api_representation(self, value, context=None):
+        return {"url": value.url, "html": value.html}
+
+
 # StreamBlocks
 class BaseStreamBlock(StreamBlock):
     """
@@ -126,7 +131,7 @@ class BaseStreamBlock(StreamBlock):
     )
     image_block = CaptionedImageBlock()
     block_quote = BlockQuote()
-    embed_block = EmbedBlock(
+    embed_block = CustomEmbedBlock(
         help_text="Insert an embed URL e.g https://www.youtube.com/watch?v=SGJFWirQ3ks",
         icon="media",
         template="blocks/embed_block.html",