Hello guys,
I'm Carl Collins from Cameroon. I'm working on this Django Project and I got stuck . Need help.The first thing I would love to ask is about performing SQL queries in Django use Django ORM. Presume I have something like this:
connection = sqlite.connect('data.db')
cursor = connection.cursor()
query = "SELECT * FROM items"
result = cursor.execute(query)
properties = []
for row in result:
items.append({})
connection.close()
print(json.dumps({'properties': properties})
I would love Django to run this automatically i.e fetch some field from the database each time a button is clicked and do a post request to an API using the json returned as the body of the request
NB: The data in the database is populated using a django form and I would love to use the same data to do a post request to an api. The API requires that the post body be in json format like
{
"currency": "",
"customerName": "",
"description": "",
"email": "",
"expiryDate": "",
"id": {
"uuid": "",
"version": ""
},
"items": [
{
"itemId": "",
"particulars": "",
"quantity": x,
"subTotal": y,
"unitCost": z
},
{
"itemId": " ",
"particulars": " ",
"quantity": j,
"subTotal": k,
"unitCost": l
}
],
"langKey": "en",
"merchantReference": " ",
"orderDate": " ",
"phoneNumber": " ",
"receiptUrl": " ",
"totalAmount": n
}
Thanks in advance
Cheers
Carl