Use def list function in ViewSets OR def get in ApiViews

you can do : - 
response_data = {
   'data': {
      '*agent_info*': agent_info_serializer(data=agent_info_data).data,
      'team_info': team_info_serializer(data=team_info_data).data
}
}

Then you can simply return the response with response_data in the body.
On Thursday, 27 May 2021 at 05:34:18 UTC+5:30 [email protected] wrote:

> You will have to write your own code to do this.
> You can convert an OrderedDict to a standard dict like this value = 
> dict(OrderedDict(...))
>
> ~Carl
>
> On Wed, May 26, 2021 at 5:01 PM Dana Adams <[email protected]> wrote:
>
>> This may be more of a Django than Django Rest question - I am new to both 
>> - but I thought I'd start here.... 
>>
>> I've got two objects of type *<class 
>> 'rest_framework.utils.serializer_helpers.ReturnDict'>* that I'd like to 
>> combine and then feed back into Response()
>>
>> *Object **1*
>>
>> {'data':
>> OrderedDict([('agent_info', [
>> OrderedDict([('agent', OrderedDict([('id', 10001), ('name', 'Jimmy 
>> McBride')])),
>> ('silence', OrderedDict([('averagePercent', 0.15), ('averageSeconds', 
>> 21.3),('percentAgent', 0.71), ('percentCustomer', 0.29)])),
>> ('calls', 14)]),
>> OrderedDict([('agent', OrderedDict([('id', 10002), ('name', 'Sally 
>> Walker')])),
>> ('silence', OrderedDict([('averagePercent', 0.24), ('averageSeconds', 
>> 26.5),('percentAgent', 0.65), ('percentCustomer', 0.35)])),
>> ('calls', 20)])
>> ])])
>> }
>>
>> Object *2*
>>
>> {'data':
>> OrderedDict([('team_info', [
>> OrderedDict([('silence', OrderedDict([('averagePercent', 0.21), (
>> 'averageSeconds', 24.8), ('percentAgent', 0.68), ('percentCustomer', 0.32
>> )])),
>> ('calls', 34)])
>> ])])
>> }
>>
>> How can I combine these such that the resulting json response, produced 
>> by Response(), looks like:
>>
>> {
>> "data": {
>> "agent_info": [
>> {
>> "agent": {
>> "id": 10001,
>> "name": "Jimmy McBride"
>> },
>> "silence": {
>> "averagePercent": 0.15,
>> "averageSeconds": 21.3,
>> "percentAgent": 0.71,
>> "percentCustomer": 0.29
>> },
>> "calls": 14,
>> },
>> {
>> "agent": {
>> "id": 10002,
>> "name": "Sally Walker"
>> },
>> "silence": {
>> "averagePercent": 0.24,
>> "averageSeconds": 26.5,
>> "percentAgent": 0.65,
>> "percentCustomer": 0.35
>> },
>> "calls": 20,
>> },
>> ],
>> "team_info": [
>> {
>> "silence": {
>> "averagePercent": 0.21,
>> "averageSeconds": 24.8,
>> "percentAgent": 0.68,
>> "percentCustomer": 0.32
>> },
>> "calls": 34
>> }
>> ]
>> }
>> }
>>
>>
>> Thanks!
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django REST framework" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-rest-framework/dfe936af-3abd-40e1-85c8-cddf61caa5fbn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-rest-framework/dfe936af-3abd-40e1-85c8-cddf61caa5fbn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
>
> -------------------------------------------------------------------------------
> Carl J. Nobile (Software Engineer)
> [email protected]
>
> -------------------------------------------------------------------------------
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/498915d4-9f99-454a-952e-4ce121500154n%40googlegroups.com.

Reply via email to