Reputation: 540
I am trying to add a value to my response that is not in my models fields. For example, please take a look at the code below
for Me in Sections:
Parts = Part.objects.filter(Section=Me.id)
for Me in Parts:
FieldCount = Field.objects.filter(Req=True, Visible=True, Part=Me.id).count()
Counter += FieldCount
RequiredField = {'FieldsRequired': Counter}
serializer = ApplicationSerializer(App)
return Response(RequiredField)
I want to be able to send serializer.data in the Response and RequiredField in the Response.
Upvotes: 1
Views: 160
Reputation: 4487
I'm not quite sure whether I understand what you want but you can add additional values to your response by simply extending the data dictionary:
serializer = MyModelSerializer(object)
data = serializer.data
data['any_key'] = 'Any Value'
return Response(data)
Upvotes: 2