-2

I have a Django model that looks like the following:

[
    {
        "ticker": "AAPL",
        "balance_sheet": [],
        "income_statement": [],
        "cash_flows": []
    },
    {
        "ticker": "MSFT",
        "balance_sheet": [],
        "income_statement": [],
        "cash_flows": []
    }
]

I want to add in the income_statement data using the requests.post function but cannot figure out how the data should be structured. I get a 400 BAD REQUEST response from the server.

What is the problem ?

r = requests.post('http://localhost:8000/stocks/', data={ 'ticker': 'MSFT',
                                                        'income_statement': [{
                                                             'annualNetIncomeContinuousOperations': 45687000000,
                                                             'annualTaxEffectOfUnusualItems': 0,
                                                             'annualNetIncomeFromContinuingOperationNetMinorityInterest': 45687000000,
                                                             'annualTotalOperatingIncomeAsReported': 60024000000,
                                                              ... , 
                                                              ... , 
                                                              ...
                                         }]
                                      }
)
Aran Freel
  • 3,085
  • 5
  • 29
  • 42

1 Answers1

0

the reason this doesn't work is because of a concept called nested serialization. more info can be found at the following link Django REST Framework POST nested objects

Aran Freel
  • 3,085
  • 5
  • 29
  • 42