Created
July 26, 2013 01:11
-
-
Save vvikramjhu/6085243 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Question --- so suppose I have two tables as below. items.id is fk and references invoice.key1 which is pk . now on the server side I have collected all rows or table1 in cur1 and table2 in cur2. What I want is to print table1 and then for each pk print corresponding table2 elements . All of this on the html . how to do this . | |
sample result will be like -- | |
invoice.id invoice.name invoice.telephone items.id1 items.name1 ....... | |
items.id1 items.name2 .......... | |
items.id1 items.name3 ........ | |
the sql schema | |
drop table if exists invoice; | |
drop table if exists items; | |
create table invoice( | |
id integer primary key autoincrement, | |
nameOfPerson text not null, | |
telephone integer , | |
currentDateTime integer not null | |
); | |
create table items( | |
id integer , | |
itemId varchar, | |
item text , | |
itemSize varchar , | |
itemQuant int, | |
PRIMARY KEY (id, item), | |
FOREIGN KEY (id) REFERENCES invoice(id) | |
); | |
views.py code | |
cur.execute('select * from invoice') | |
displayDataInfo = [dict(id=row[0], name=row[1], telephone=row[2] ) for row in cur.fetchall()] | |
cur.execute('select* from items') | |
displayDataItems = [dict(id=row[0], itemid=row[1], itemName=row[2], itemSize=row[3], itemQuantity=row[4] ) for row in cur.fetchall()] | |
Html code --- | |
<div id="currentOrdersList" border="none"> | |
{% for x in displayDataInfo %} | |
<div id="orderClass"> | |
<li id="orderedItemsLister">{{x.name}}</li> | |
<li id="orderedItemsLister">{{x.telephone}}</li> | |
{% if displayDataItems.id == display.id %} | |
----------------------------------------------------------what do I write here ? | |
</div> | |
{% endfor %} | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment