samedi 5 février 2022

Ember 4.1. Django rest json api. Access field choices from OPTIONS request in Ember data model or elsewhere

My DRF JSON API backend responds with a JSON on OPTIONS request. The OPTIONS response includes field choices declared on Django model. On my frontend, in my Ember 4.1 app with default JSONApiAdapter I want to use these exact same choices on my form select. Is there a way to access these choices on my Ember model or somewhere else? and if so, How do I do it? Here's an example OPTIONS response:

{
    "data": {
        "name": "Names List",
        "description": "API endpoint for Names",
        "renders": [
            "application/vnd.api+json",
            "text/html"
        ],
        "parses": [
            "application/vnd.api+json",
            "application/x-www-form-urlencoded",
            "multipart/form-data"
        ],
        "allowed_methods": [
            "GET",
            "POST",
            "HEAD",
            "OPTIONS"
        ],
        "actions": {
            "POST": {
                "name": {
                    "type": "String",
                    "required": true,
                    "read_only": false,
                    "write_only": false,
                    "label": "Name",
                    "help_text": "name",
                    "max_length": 255
                },
                "name-type": {
                    "type": "Choice",
                    "required": true,
                    "read_only": false,
                    "write_only": false,
                    "label": "Name type",
                    "help_text": "Name type",
                    "choices": [
                        {
                            "value": "S",
                            "display_name": "Short"
                        },
                        {
                            "value": "L",
                            "display_name": "
                    ]
                }
            }
        }
    }
}



Aucun commentaire:

Enregistrer un commentaire