Performing SQL queries on SQLite database

22 views
Skip to first unread message

carl collins

unread,
Mar 23, 2019, 3:27:51 PM3/23/19
to django...@googlegroups.com
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

carl collins

unread,
Mar 25, 2019, 3:39:46 AM3/25/19
to django...@googlegroups.com
Hello,
 Please I need advice on how I can go on with this.
Thanks 
Reply all
Reply to author
Forward
0 new messages