Nested relationships wagtail api

boydbueno

I have the following data structure:

{"related_cases": [
    {
        "type": "related_case_block",
        "value": {
            "case": 13,
            "short_text": "Case 2 is related!"
        },
        "id": "3aec5efe-55dc-441f-aa5c-fbbb801d237a"
    }
]}

Related cases is a streamfield with blocks inside. Each block holds a reference to another case page. Which is 13 in this case.

I would like to include some fields from this case into the response, like this:

 {"related_cases": [
    {
        "type": "related_case_block",
        "value": {
            "case": {
                "id": 13,
                "title": "Case 2"
            },
            "short_text": "Case 2 is related!"
        },
        "id": "3aec5efe-55dc-441f-aa5c-fbbb801d237a"
    }
]}

Can anyone explain how I would accomplish this?

gasman

Assuming you've defined related_case_block as a subclass of StructBlock, you can override the get_api_representation method on that class:

class RelatedCaseBlock(blocks.StructBlock):
    # ...
    def get_api_representation(self, value, context=None):
        return {
            'case': {
                'id': value['case'].id
                'title': value['case'].title
            },
            'short_text': value['short_text']
        }

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Nested Mapped Laravel Query with Relationships

分類Dev

when is it mandatory to use fluent api when defining relationships

分類Dev

WagtailをAPIレイヤーとして使用する

分類Dev

RESTful API - Handling nested relations

分類Dev

Facebook APIで、relationships_statusを取得していません

分類Dev

jQuery nested query to JSON API with google charts

分類Dev

java nested http call api library

分類Dev

Neomodel relationships

分類Dev

Django Wagtail Pages -1

分類Dev

Wagtail not indexing body field

分類Dev

Adding relationships to an array of relationships in hyperledger-composer

分類Dev

JPA Criteria API: How to select property in nested collection

分類Dev

Microsoft Graph API - Office 365 Access SharePoint Nested Folder Items

分類Dev

Java: Find common item on nested list using Stream API

分類Dev

How to display the nested array data in react native from API?

分類Dev

Vue use v-for to iterate over an nested array of API response

分類Dev

Extract nested objects in an object using dataset api in spark

分類Dev

React-typescript-Redux-toolkit: failed to fetch nested api

分類Dev

Accessing nested values in JSON data from Twitch API

分類Dev

Inserting a Row in BigQuery with Nested Record using C# API

分類Dev

jQuery nested each loop not working as expected using Trello API

分類Dev

Add streamfield to search index in Wagtail

分類Dev

RichTextField uneditable with Draftail in Wagtail 2.0

分類Dev

Having a bootstrap carousel for Wagtail problem

分類Dev

Wagtail: How to override default ImageEmbedHandler?

分類Dev

Wagtail 圖像的替代文本

分類Dev

Laravel Recursive Relationships

分類Dev

Cascading "@Any" relationships

分類Dev

Rails active record relationships

Related 関連記事

  1. 1

    Nested Mapped Laravel Query with Relationships

  2. 2

    when is it mandatory to use fluent api when defining relationships

  3. 3

    WagtailをAPIレイヤーとして使用する

  4. 4

    RESTful API - Handling nested relations

  5. 5

    Facebook APIで、relationships_statusを取得していません

  6. 6

    jQuery nested query to JSON API with google charts

  7. 7

    java nested http call api library

  8. 8

    Neomodel relationships

  9. 9

    Django Wagtail Pages -1

  10. 10

    Wagtail not indexing body field

  11. 11

    Adding relationships to an array of relationships in hyperledger-composer

  12. 12

    JPA Criteria API: How to select property in nested collection

  13. 13

    Microsoft Graph API - Office 365 Access SharePoint Nested Folder Items

  14. 14

    Java: Find common item on nested list using Stream API

  15. 15

    How to display the nested array data in react native from API?

  16. 16

    Vue use v-for to iterate over an nested array of API response

  17. 17

    Extract nested objects in an object using dataset api in spark

  18. 18

    React-typescript-Redux-toolkit: failed to fetch nested api

  19. 19

    Accessing nested values in JSON data from Twitch API

  20. 20

    Inserting a Row in BigQuery with Nested Record using C# API

  21. 21

    jQuery nested each loop not working as expected using Trello API

  22. 22

    Add streamfield to search index in Wagtail

  23. 23

    RichTextField uneditable with Draftail in Wagtail 2.0

  24. 24

    Having a bootstrap carousel for Wagtail problem

  25. 25

    Wagtail: How to override default ImageEmbedHandler?

  26. 26

    Wagtail 圖像的替代文本

  27. 27

    Laravel Recursive Relationships

  28. 28

    Cascading "@Any" relationships

  29. 29

    Rails active record relationships

ホットタグ

アーカイブ