Link where I got info from itertools
https://stackoverflow.com/questions/44000727/iterate-over-two-lists-with-different-lengths
import itertools
some of the code in history application.
db_stock_info = db.execute("SELECT * FROM stock_info WHERE id = :present_id",
present_id = current_id)
db_history = db.execute("SELECT * FROM history WHERE id = :present_id",
present_id = current_id)
# https://stackoverflow.com/questions/44000727/iterate-over-two-lists-with-different-lengths
numbers_rows = itertools.zip_longest(db_history, db_rows_stock_info)
history.html
{% extends "layout.html" %}
{% block title %}
history
{% endblock title %}
{% block main %}
<table>
<tr>
<th> <p> SYMBOL </p> </th>
<th> <p> SHARES </p> </th>
<th> <p> PRICE </p> </th>
<th> <p> TRANSACTED </p> </th>
</tr>
<tr>
{% for i in range(number_rows) %}
<th> <p> {{db_stock_info[i]["stock_symbol"]}} </p> </th>
<th> <p> {{db_history[i]["shares"]}} </p> </th>
<th> <p> {{db_stock_info[i]["stock_price"]}} </p> </th>
<th> <p> {{db_history[i]["time_stamp"]}} </p> </th>
{% endfor %}
</tr>
</table>
{% endblock %}
Without going into the full detail of the tables
history table
id | shares
1 1
1 -1
1 1
stock_info table:
id | shares
1 1
render_template
? Especially I don't get why you seem to separate the symbol and price at buy/sell time into another table. It's part of the transaction. Or are those tables not related at all? – Blauelf Sep 10 '19 at 8:19INSERT
, but neverUPDATE
orDELETE
. – Blauelf Sep 18 '19 at 15:30id
in both extra tables stands for. Maybe you could JOIN on these. But the result might not make much sense. – Blauelf Sep 18 '19 at 18:42