Multiple dicts for querying multiple tables

28 views
Skip to first unread message

En Ware

unread,
Mar 20, 2018, 9:59:21 AM3/20/18
to web2py-users
Hello,

    Trying to get the full count on three different tables. Below is a sample code. I am only able to call one count at a time. Is it possible to query all three of these and show them in a view? 

def index():
    get_foxtel_count=db(db.foxtel_hunter.id > 0).count()
    get_lgi_count=db(db.lgi_hunter.id > 0).count()
    get_adobe_count=db(db.adobe_hunter.id > 0).count()
    #return dict(get_foxtel_count=get_foxtel_count)
    #return dict(get_lgi_count=get_lgi_count)
    #return dict(get_adobe_count=get_adobe_count)

    return dict()


Anthony

unread,
Mar 20, 2018, 10:19:08 AM3/20/18
to web2py-users
A dict can have multiple keys, so feel free to return a dict that includes all three results. Of course, you can also put all three values into a single object (e.g., a dict, list, or tuple), and then just return that single object to the view.

Anthony

En Ware

unread,
Mar 20, 2018, 10:34:42 AM3/20/18
to web2py-users
Anthony,
  
   I'm probably doing something wrong with the view then,

I get an error if I try to call the dict in a view.

{{extend 'layout.html'}}

<h1>Watch and Defend </h1>


<ul>
     Links:
    <ol><a href="http://localhost:8081/Hunter/default/foxtel_search">Show Foxtel Records      {{=get_foxtel_count}}

        <br>
        <a href="http://localhost:8081/Hunter/default/lgi_search">Show LGI Records            {{=get_lgi_count}}
        <br>
        <a href="http://localhost:8081/Hunter/default/adobe_search">Show Adobe Records        {{=get_adobe_count}}
    </ol>
</ul>

1.
2.
3.
4.
5.
6.
Traceback (most recent call last):
File "/Users/aaronm/.env/python/web2py/web2py/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
File "/Users/aaronm/.env/python/web2py/web2py/applications/Hunter/views/default/index.html", line 116, in <module>
NameError: name 'get_lgi_count' is not defined

Anthony

unread,
Mar 20, 2018, 12:45:36 PM3/20/18
to web2py-users
You are returning an empty dict - you need to add those three items to it.
Reply all
Reply to author
Forward
0 new messages