Django DRF how to use to_representation and to_internal_value? -


the documentation brief, , i'm unable figure out how use reading source code.

here want accomplish in pseudocode:

def transform_result(self, data):     ret = {}     entry in data:         type = entry['type']         if type in ret:             ret[type].add({entry['id'], entry['tag']})         else:             new_type = ret.add(type)             new_type.add({entry['id'], entry['tag']})     return ret 

which should take this:

[     {         "id": 1,         "type": "color",         "tag": "blue"     },     {         "id": 2,         "type": "color",         "tag": "red"     },     {         "id": 3,         "type": "shape",         "tag": "square"     }, ] 

and transform this:

[     {         "type": "color",         "tags": [             {                 "id": 1,                 "tag": "blue"             },             {                 "id": 2,                 "tag": "red"             }         ]     },     {         "type": "shape",         "tags": [             {                 "id": 3,                 "tag": "square"             }         ]     } ] 

should done using to_representation , to_internal_value? if so, how done?


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -