0

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

enter image description here

enter image description here

enter image description here

enter image description here

18
  • What are those two tables (which columns, what they contain, when they are filled with which data), what do you want to show, how do you call 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:19
  • I posted enough details of the tables to illustrate the problem in the original post. Any advice? @Blauelf – grggthwrth Sep 11 '19 at 19:59
  • I meant to say I added details. I did not want to state that my post was good from the beginning. – grggthwrth Sep 11 '19 at 20:05
  • 1
    Keep all the transaction-related data in one table, a table in which you INSERT, but never UPDATE or DELETE. – Blauelf Sep 18 '19 at 15:30
  • 1
    I still don't understand the meaning of your tables, and you still haven't answered what the id 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

You must log in to answer this question.

Browse other questions tagged .