Selecting the last item in q or a ends up with:
<Row {'message': '....strings....'', 'id': 8135L}>
How do I remove this to get only the strings without doing a loop?

On Mon, Jun 11, 2018 at 10:32 PM Maurice Waka <[email protected]> wrote:

> Thank you. Am working on it.
>
> On Mon, 11 Jun 2018, 22:29 Anthony <[email protected]> wrote:
>
>> Below is the start of the controller code, containing several hundred
>>> lines:
>>>
>>
>> Hard to know what's going on without the code. Consider profiling the
>> code, or simply pick some spots you think might be taking long and return
>> early to see if things speed up.
>>
>>
>>>     form = SQLFORM(Post, formstyle='table3cols',)
>>>     if form.process().accepted:
>>>         pass
>>>
>>
>> No need for the "if" or the ".accepted" here. Just do:
>>
>> form = SQLFORM(Post, formstyle='table3cols').process()
>>
>>
>>>     messagev = ''
>>>     for r in db(db.post.author == auth.user.id).select(db.post.ALL):
>>>         messagev = r.message
>>>
>>
>> There is no reason to select the entire table and loop over it --
>> ultimately, you simply end up with the message from the last record.
>> Replace the above with:
>>
>> row = db(db.post.author == auth.user.id).select(db.post.id, db.post.
>> message,
>>                                                 orderby=~db.post.id,
>>                                                 limitby=(0, 1)).first()
>>
>> messagev = row.message if row else None
>>
>> At the limitby(0,2) am using the js code below to obtain the string for
>>> the q, and a.
>>>
>>
>> Again, no reason to select the last two records if you end up using only
>> the last record in your code.
>>
>> Anthony
>>
>> --
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "web2py-users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/web2py/O6CxDRViyNA/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to