<div dir="ltr"><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6">Boom! Alexander has spoken :)</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 20, 2014 at 11:04 PM, Alexander Kozlovsky <span dir="ltr"><<a href="mailto:alexander.kozlovsky@gmail.com" target="_blank">alexander.kozlovsky@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi guys!<br><br>It seems that we should add several convenience methods to collections, so it will be possible to do any of the following:<br><br>{% for comment in post.comments.order_by(Comment.id) %}<br><br>{% for comment in post.comments.filter(lambda c: c.date >= yesterday ).order_by(lambda c: desc(c.date)) %}<br><br>All of this can be achieved today, but with more complex syntax.<br><br>Also, we probably can automatically sort collection items by primary key during iteration, if no explicit ordering was set. In some cases the ordering is unnecessary, because conceptually the collection is just an unordered set. But most users probably expect that the result of collection iteration is predictable.<br><br><div><span class="">> <font face="arial, sans-serif">IMO, the database should be doing the sorting in the query, not sorted()</font><br><br></span><font face="arial, sans-serif">Actually I prefer to do sorting in memory (if we need to process entire collection), because it puts less burden on the database, and the application code can be easily scaled by running multiple parallel processes. But if only a subset of records is retrieved from the database, then sorting should be done in the query, in order to avoid fetching of unnecessary data. So maybe it will make sense to add two separate methods: `post.comments.sort_by(Comment.id)` to do sorting in memory and `post.comments.order_by(Comment.id).page(1, pagesize=10)` to add ORDER BY...LIMIT sections to the query.<br><br>I hope that we can add `order_by` and `filter` methods to collections in our next release )<br><br></font></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 20, 2014 at 6:54 PM, Matthew Bell <span dir="ltr"><<a href="mailto:matthewrobertbell@gmail.com" target="_blank">matthewrobertbell@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">IMO, the database should be doing the sorting in the query, not sorted()<br></div><div class="gmail_extra"><div><div><br><div class="gmail_quote">On 20 November 2014 15:16, Gamesbrainiac <span dir="ltr"><<a href="mailto:gamesbrainiac@gmail.com" target="_blank">gamesbrainiac@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:'trebuchet ms',sans-serif;color:rgb(61,133,198)">Well, I have set up the following example for you, see if it works for you:</div><div class="gmail_default" style="font-family:'trebuchet ms',sans-serif;color:rgb(61,133,198)"><br></div><div class="gmail_default"><font face="trebuchet ms, sans-serif" color="#3d85c6"><a href="https://gist.github.com/gamesbrainiac/5eacc2a5c1b0fb1cd52f" target="_blank">https://gist.github.com/gamesbrainiac/5eacc2a5c1b0fb1cd52f</a></font><br></div><div class="gmail_default"><font face="trebuchet ms, sans-serif" color="#3d85c6"><br></font></div><div class="gmail_default"><font face="trebuchet ms, sans-serif" color="#3d85c6">Hope this helps :)</font></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 20, 2014 at 7:08 PM, Pedro Baumann <span dir="ltr"><<a href="mailto:ondoheer@gmail.com" target="_blank">ondoheer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Precisely! That's my problem. </p><div><div>
<div class="gmail_quote">On 20 Nov 2014 02:21, "Gamesbrainiac" <<a href="mailto:gamesbrainiac@gmail.com" target="_blank">gamesbrainiac@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6">I think I get your problem now. Right now, it is ordering by post ID. Do you want the comments of a particular post to be ordered by ID, or do you want something like:</div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6"><br></div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6">Post 1:</div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6">    Comment 1</div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6">    Comment 2</div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6">Post 2:</div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6">   Comment 1</div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6">   Comment 2</div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6"><br></div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:#3d85c6">?</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 20, 2014 at 12:19 PM, Pedro Baumann <span dir="ltr"><<a href="mailto:ondoheer@gmail.com" target="_blank">ondoheer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello Gamebrainiac<div><br></div><div>Thanks for the link, it seems really interesting. </div><div><br></div><div>I have tried both your suggestions and both gave mme the same problem.</div><div><br></div><div>They both return the Post object ordered by id, same as my code did. The problem is that somehow when I iterate through the posts like soÑ</div><div><br></div><div>    {% for post in posts %}</div><span><div>       {% for comment in post.comments %}</div><div><br></div><div><br></div></span><div>the comments come out in any order, and they change with every request!!!!</div><div><br></div><div>That same thing happens with your suggestions.</div><div>I think this hasn't happend to me with pony before, but somehow it does now.  Is there a way to sort the linked table from jinja?</div><div><br></div><div>something like post.comments.order_by(id)?<br><div><br></div><div><br></div></div></div><div class="gmail_extra"><span><br clear="all"><div><div><div dir="ltr"><div><b><br></b></div><b><div><b><br></b></div><div><b><br></b></div><div><b><br></b></div>Pedro Baumann Cornejo</b><div>Psicólogo - Psicoterapeuta - Flores de Bach</div><div>Francisco de Paula Ugarriza 309 dpto. 102 Miraflores.</div><div>Lima</div><div>Perú</div></div></div></div>
<br></span><div><div><div class="gmail_quote">On Thu, Nov 20, 2014 at 1:02 AM, Gamesbrainiac <span dir="ltr"><<a href="mailto:gamesbrainiac@gmail.com" target="_blank">gamesbrainiac@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:rgb(61,133,198)">In addendum, this is the exact part where I talk about querying: <a href="http://nafiulis.me/a-todo-app-with-flask-and-pony.html#id4" target="_blank">http://nafiulis.me/a-todo-app-with-flask-and-pony.html#id4</a><br></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 20, 2014 at 12:01 PM, Gamesbrainiac <span dir="ltr"><<a href="mailto:gamesbrainiac@gmail.com" target="_blank">gamesbrainiac@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:rgb(61,133,198)">Try using:<br><br><span style="font-family:monospace">'"SELECT * FROM "post" ORDER BY "post"."id"'</span><br><br></div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:rgb(61,133,198)">If I were you, I'd do the following in pony:<br><br></div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:rgb(61,133,198)"><span style="font-family:monospace">Post.select().order_by(Post.id)</span><br><br></div><div class="gmail_default" style="font-family:trebuchet ms,sans-serif;color:rgb(61,133,198)">Also, my post on Pony might be worth a look -> <a href="http://nafiulis.me/a-todo-app-with-flask-and-pony.html" target="_blank">http://nafiulis.me/a-todo-app-with-flask-and-pony.html</a><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Thu, Nov 20, 2014 at 11:43 AM, Pedro Baumann <span dir="ltr"><<a href="mailto:ondoheer@gmail.com" target="_blank">ondoheer@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">Hello,<div><br></div><div>first of all I want to thank you for creating such an intuitive and pythonic ORM, I have enjoyed every minute if used it, it's most intuitive and it really heps code readability.</div><div><br></div><div>I'm having a small problem with my latest project, I hope you can help me.</div><div><br></div><div>I'm developing a web app that has a basic "blog like" module.</div><div><br></div><div>Post->Comments->Replies</div><div><br></div><div>I'm using Flask as a framework. </div><div><br></div><div>I'm passing <br clear="all"><div><div><div dir="ltr"><div><b><br></b></div><div><b>posts = Post.select_by_sql('SELECT * FROM post ORDER BY id')<br></b></div><div><b><br></b></div><div>to the template, and then iterating through it to print the comments as in </div><div style="font-weight:bold"><b><br></b></div><div><div style="font-weight:bold">{% for comment in post.comments %}</div><div style="font-weight:bold">  {% if loop.index > numberComments %}{% break %}{% endif %} </div><div style="font-weight:bold"> // code code code (HTML)</div><div style="font-weight:bold">{% endfor %}</div><div style="font-weight:bold"><br></div><div>the problem is the comments come out in random order, varying on each iteration.</div></div><div><br></div><div>I need to be able to print the comments in order for my ajax functions that retrieve more comments to work.</div><div><br></div><div>I think I am missing something here. </div><div><br></div><div>Thanks !</div><div style="font-weight:bold"><b><br></b></div><b>Pedro Baumann Cornejo</b><div>Psicólogo - Psicoterapeuta - Flores de Bach</div><div>Francisco de Paula Ugarriza 309 dpto. 102 Miraflores.</div><div>Lima</div><div>Perú</div></div></div></div>
</div></div>
<br></div></div>_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org" target="_blank">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">/ponyorm-list</a><br>
<br></blockquote></div><span><font color="#888888"><br><br clear="all"><br>-- <br><div><div dir="ltr"><div><font face="trebuchet ms, sans-serif" size="4" color="#6fa8dc">Kind Regards,</font></div><div><img src="https://brnbcg.blu.livefilestore.com/y1mIyqRuYWMVkEp1XgqnpPJw31rRYoNvXRcLpo1WOUfIx-d9b0krZq2EJ4vUjOgoHcfZow1IZifvV3JxEuWl7yinOPYSMwlrPk7rFfWQ7RMTlkgQ9uTAq0uNQ/Signature1.png?psid=1" height="69" width="96"><br></div><div></div><div><span style="font-family:'trebuchet ms',sans-serif;font-size:large"><font color="#6fa8dc">Quazi Nafiul Islam</font></span></div></div></div>
</font></span></div>
</blockquote></div><br><br clear="all"><br>-- <br><div><div dir="ltr"><div><font face="trebuchet ms, sans-serif" size="4" color="#6fa8dc">Kind Regards,</font></div><div><img src="https://brnbcg.blu.livefilestore.com/y1mIyqRuYWMVkEp1XgqnpPJw31rRYoNvXRcLpo1WOUfIx-d9b0krZq2EJ4vUjOgoHcfZow1IZifvV3JxEuWl7yinOPYSMwlrPk7rFfWQ7RMTlkgQ9uTAq0uNQ/Signature1.png?psid=1" height="69" width="96"><br></div><div></div><div><span style="font-family:'trebuchet ms',sans-serif;font-size:large"><font color="#6fa8dc">Quazi Nafiul Islam</font></span></div></div></div>
</div>
</div></div><br>_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org" target="_blank">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">/ponyorm-list</a><br>
<br></blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org" target="_blank">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">/ponyorm-list</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div><font face="trebuchet ms, sans-serif" size="4" color="#6fa8dc">Kind Regards,</font></div><div><img src="https://brnbcg.blu.livefilestore.com/y1mIyqRuYWMVkEp1XgqnpPJw31rRYoNvXRcLpo1WOUfIx-d9b0krZq2EJ4vUjOgoHcfZow1IZifvV3JxEuWl7yinOPYSMwlrPk7rFfWQ7RMTlkgQ9uTAq0uNQ/Signature1.png?psid=1" height="69" width="96"><br></div><div></div><div><span style="font-family:'trebuchet ms',sans-serif;font-size:large"><font color="#6fa8dc">Quazi Nafiul Islam</font></span></div></div></div>
</div>
<br>_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org" target="_blank">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">/ponyorm-list</a><br>
<br></blockquote></div>
</div></div><br>_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org" target="_blank">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">/ponyorm-list</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div><font face="trebuchet ms, sans-serif" size="4" color="#6fa8dc">Kind Regards,</font></div><div><img src="https://brnbcg.blu.livefilestore.com/y1mIyqRuYWMVkEp1XgqnpPJw31rRYoNvXRcLpo1WOUfIx-d9b0krZq2EJ4vUjOgoHcfZow1IZifvV3JxEuWl7yinOPYSMwlrPk7rFfWQ7RMTlkgQ9uTAq0uNQ/Signature1.png?psid=1" height="69" width="96"><br></div><div></div><div><span style="font-family:'trebuchet ms',sans-serif;font-size:large"><font color="#6fa8dc">Quazi Nafiul Islam</font></span></div></div></div>
</div>
</div></div><br>_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org" target="_blank">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">/ponyorm-list</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br></div></div><div>Regards,<br><br>Matthew Bell<br></div>
</div>
<br>_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org" target="_blank">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">/ponyorm-list</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">/ponyorm-list</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><font size="4" face="trebuchet ms, sans-serif" color="#6fa8dc">Kind Regards,</font></div><div><img src="https://brnbcg.blu.livefilestore.com/y1mIyqRuYWMVkEp1XgqnpPJw31rRYoNvXRcLpo1WOUfIx-d9b0krZq2EJ4vUjOgoHcfZow1IZifvV3JxEuWl7yinOPYSMwlrPk7rFfWQ7RMTlkgQ9uTAq0uNQ/Signature1.png?psid=1" width="96" height="69"><br></div><div></div><div><span style="font-family:'trebuchet ms',sans-serif;font-size:large"><font color="#6fa8dc">Quazi Nafiul Islam</font></span></div></div></div>
</div>