I have a django app where i have an api defined as follows:
Here is what is what i am sending in my json from my api.py:
class studentList(APIView):
def get(self, request, pk, format=None):
student_detail = Student.objects.filter(student_id = pk)
serialized_student_detail = studentSerializer(student_detail, many=True)
return Response(serialized_student_detail.data)
I have another variable named status which i am calculating with the help of reverse lookups. What i am trying to achieve is to send another field named status along with the above json values. Since my model does not have a status field in it, How do i achieve this?
What you may need is a SerializerMethodField (http://www.django-rest-framework.org/api-guide/fields/#serializermethodfield). Note that by default it is a read only field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With