[PonyORM-list] Problem with iterated linked table

Pedro Baumann ondoheer at gmail.com
Thu Nov 20 06:19:52 UTC 2014


Hello Gamebrainiac

Thanks for the link, it seems really interesting.

I have tried both your suggestions and both gave mme the same problem.

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Ñ

    {% for post in posts %}
       {% for comment in post.comments %}


the comments come out in any order, and they change with every request!!!!

That same thing happens with your suggestions.
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?

something like post.comments.order_by(id)?







*Pedro Baumann Cornejo*
Psicólogo - Psicoterapeuta - Flores de Bach
Francisco de Paula Ugarriza 309 dpto. 102 Miraflores.
Lima
Perú

On Thu, Nov 20, 2014 at 1:02 AM, Gamesbrainiac <gamesbrainiac at gmail.com>
wrote:

> In addendum, this is the exact part where I talk about querying:
> http://nafiulis.me/a-todo-app-with-flask-and-pony.html#id4
>
> On Thu, Nov 20, 2014 at 12:01 PM, Gamesbrainiac <gamesbrainiac at gmail.com>
> wrote:
>
>> Try using:
>>
>> '"SELECT * FROM "post" ORDER BY "post"."id"'
>>
>> If I were you, I'd do the following in pony:
>>
>> Post.select().order_by(Post.id)
>>
>> Also, my post on Pony might be worth a look ->
>> http://nafiulis.me/a-todo-app-with-flask-and-pony.html
>>
>> On Thu, Nov 20, 2014 at 11:43 AM, Pedro Baumann <ondoheer at gmail.com>
>> wrote:
>>
>>> Hello,
>>>
>>> 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.
>>>
>>> I'm having a small problem with my latest project, I hope you can help
>>> me.
>>>
>>> I'm developing a web app that has a basic "blog like" module.
>>>
>>> Post->Comments->Replies
>>>
>>> I'm using Flask as a framework.
>>>
>>> I'm passing
>>>
>>>
>>> *posts = Post.select_by_sql('SELECT * FROM post ORDER BY id')*
>>>
>>> to the template, and then iterating through it to print the comments as
>>> in
>>>
>>> {% for comment in post.comments %}
>>>   {% if loop.index > numberComments %}{% break %}{% endif %}
>>>  // code code code (HTML)
>>> {% endfor %}
>>>
>>> the problem is the comments come out in random order, varying on each
>>> iteration.
>>>
>>> I need to be able to print the comments in order for my ajax functions
>>> that retrieve more comments to work.
>>>
>>> I think I am missing something here.
>>>
>>> Thanks !
>>>
>>> *Pedro Baumann Cornejo*
>>> Psicólogo - Psicoterapeuta - Flores de Bach
>>> Francisco de Paula Ugarriza 309 dpto. 102 Miraflores.
>>> Lima
>>> Perú
>>>
>>> _______________________________________________
>>> ponyorm-list mailing list
>>> ponyorm-list at ponyorm.com
>>> /ponyorm-list
>>>
>>>
>>
>>
>> --
>> Kind Regards,
>>
>> Quazi Nafiul Islam
>>
>
>
>
> --
> Kind Regards,
>
> Quazi Nafiul Islam
>
> _______________________________________________
> ponyorm-list mailing list
> ponyorm-list at ponyorm.com
> /ponyorm-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20141120/92c84da9/attachment-0001.html>


More information about the ponyorm-list mailing list