update the date from the serializer with a new dict

22 views
Skip to first unread message

georgen...@gmail.com

unread,
Sep 15, 2018, 12:53:12 PM9/15/18
to Django users
I have created a simple service which returns the data from a single table based on a param in the URL as follow:
output is the json:
HTTP 200 OK
Allow: GET
Content-Type: application/json
Vary: Accept

[
   {
        "figonr": "1078924300-01",
        "description": "F150/C+W/CC/GE201S/S/OE/SE",
        "productgroup": null
   }
]

I would like to add in the json list a small dict with values like
Enter code here...{
"execution_time": "13:00"
}

so the final result will be
Enter code here...[
    {
    "figonr": "1078924300-01",
    "description": "F150/C+W/CC/GE201S/S/OE/SE",
    "productgroup": null
    },
    {
    "execution_time": "13:00"
    }
]


here is my serilalizer code
Enter code here...from rest_framework import serializers
from servicesapp.models import Figo
import datetime

class ServiceAppSerializer(serializers.ModelSerializer):
ExecutionTime = serializers.SerializerMethodField() # add field

class Meta:
model = Figo
fields=('figonr','description', 'username', 'timestmp', 'ExecutionTime')

def get_ExecutionTime(self, obj):
# here write the logic to compute the value based on object
george=1
return datetime.datetime.now()



Reply all
Reply to author
Forward
0 new messages