Hi. Well, I want to output the HTML code from database. And the HTML
code should be order by 'cost' and group_by 'category'
The database table is like below.
-----------------------------------------------
ID Category Name Cost
0 food banana $1
1 food apple $2
2 book foo $15
3 book foobar $10
4 something qwert $5
5 something poiuy $7
6 anything asdf $8
-----------------------------------------------
I want to group them by 'Category' field and order them by 'Cost'
field and output the HTML table like below
-----------------------------------------------
<table>
<tr>
<td>0</td>
<td>food<td>
<td>banana</td>
<td>$1</td>
</tr>
<tr class="children">
<td>1</td>
<td>food<td>
<td>apple</td>
<td>$2</td>
</tr>
<tr>
<td>4</td>
<td>something<td>
<td>qwert</td>
<td>$5</td>
</tr>
<tr class="children">
<td>5</td>
<td>something<td>
<td>poiuy</td>
<td>$7</td>
</tr>
<tr>
<td>6</td>
<td>anything<td>
<td>asdf</td>
<td>$8</td>
</tr>
<tr>
<td>3</td>
<td>book<td>
<td>foobar</td>
<td>$10</td>
</tr>
<tr class="children">
<td>2</td>
<td>book<td>
<td>foo</td>
<td>$15</td>
</tr>
</table>
---------------------------------------
So I wrote the code like below
---------------------------------------
...
query = session.query(orm.Some)
query = query.order_by(orm.Some.cost)
query = query.group_by(orm.Some.category)
...
---------------------------------------
Then I got a similar result as I want but not exact one. The result
was like
-----------------------------------------------
<table>
<tr>
<td>0</td>
<td>food<td>
<td>banana</td>
<td>$1</td>
</tr>
<tr class="children">
<td>1</td>
<td>food<td>
<td>apple</td>
<td>$2</td>
</tr>
<tr>
<td>4</td>
<td>something<td>
<td>qwert</td>
<td>$5</td>
</tr>
<tr class="children">
<td>5</td>
<td>something<td>
<td>poiuy</td>
<td>$7</td>
</tr>
<tr>
<td>6</td>
<td>anything<td>
<td>asdf</td>
<td>$8</td>
</tr>
<!--
The result below is wrong !!!
foo is more expensive than foobar so it should be the children of
the foobar.
-->
<tr>
<td>2</td>
<td>book<td>
<td>foo</td>
<td>$15</td>
</tr>
<tr class="children">
<td>3</td>
<td>book<td>
<td>foobar</td>
<td>$10</td>
</tr>
</table>
---------------------------------------
I know that foo.id < foobar.id but I really want to order_by 'cost'
Any idea? I need help...
* sorry about my stupid english. I'm not native.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---