Skip to main content
added 116 characters in body
Source Link
AlexandreS
  • 725
  • 1
  • 9
  • 18
  • In your Transfer model, in the transaction ForeignKey, add related_name=transfers.

  • In your TransactionSerializer, add the class attribute:

transfers = TransferSerializer(many=True)

This will give you:

  • EDIT: In your TransferSerializer, modify fields for fields=('created_at','transaction_type_id', 'transfers') This will give you:
{
  "created_at": "2019-08-18",
  "transaction_type_id": "1",
  "transfers": [
    {"transfer_type": 1, "debit": "100", ...},
    ...
  ],
}
  • In your Transfer model, in the transaction ForeignKey, add related_name=transfers.

  • In your TransactionSerializer, add the class attribute:

transfers = TransferSerializer(many=True)

This will give you:

{
  "created_at": "2019-08-18",
  "transaction_type_id": "1",
  "transfers": [
    {"transfer_type": 1, "debit": "100", ...},
    ...
  ],
}
  • In your Transfer model, in the transaction ForeignKey, add related_name=transfers.

  • In your TransactionSerializer, add the class attribute:

transfers = TransferSerializer(many=True)
  • EDIT: In your TransferSerializer, modify fields for fields=('created_at','transaction_type_id', 'transfers') This will give you:
{
  "created_at": "2019-08-18",
  "transaction_type_id": "1",
  "transfers": [
    {"transfer_type": 1, "debit": "100", ...},
    ...
  ],
}
Source Link
AlexandreS
  • 725
  • 1
  • 9
  • 18

  • In your Transfer model, in the transaction ForeignKey, add related_name=transfers.

  • In your TransactionSerializer, add the class attribute:

transfers = TransferSerializer(many=True)

This will give you:

{
  "created_at": "2019-08-18",
  "transaction_type_id": "1",
  "transfers": [
    {"transfer_type": 1, "debit": "100", ...},
    ...
  ],
}