0

I want to get all expenses in the format given below.so when I hit the URL api/expenses I get the result in the following manner and also when I call api/expenses/<id> it shows all expense with that expense id.

What Query should I use to get Output in the above format? How will my view look like? How can I separate own and lend?

Zodiac
  • 121
  • 1
  • 9
  • Please add more data about your question...what is the required format, what does "following manner" mean and what own, lend are. – p.ry May 21 '20 at 07:45
  • Hey @p.ry please visit https://stackoverflow.com/questions/61929711/reformat-django-rest-framework-serializer-to-get-output to get the whole context. – Zodiac May 21 '20 at 07:49

1 Answers1

0

Yes if you are using django then you will have to write a serializer to convert the data to your desired format after you retrieve the modal instance from the query. There are many examples given in this documentation on how to write your custom serializer. You will have to use the to_representation available on this link of documentation.

Dexter
  • 236
  • 2
  • 12