populating DB in first app run

38 views
Skip to first unread message

Carlos Cesar Caballero Díaz

unread,
Aug 28, 2015, 9:51:40 AM8/28/15
to web...@googlegroups.com
Hi, I need to add some users, and some fields to tables at the first
time that my app runs, right now I ask for fields in the tables and if
they are empty I put the values, but I don't like to query the tables in
all requests for doing this. What do you recommend me?

--
Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

Richard Vézina

unread,
Aug 28, 2015, 9:57:41 AM8/28/15
to web2py-users
fixture = False
if fixture and db(db.table.id > 0).count() == 0:
    db.table.insert(...)



--
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 web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anthony

unread,
Aug 28, 2015, 10:30:31 AM8/28/15
to web2py-users
On Friday, August 28, 2015 at 9:57:41 AM UTC-4, Richard wrote:
fixture = False
if fixture and db(db.table.id > 0).count() == 0:
    db.table.insert(...)

Or put the code in an action that requires admin permission to access.

Or use a script and run:

python web2py.py -S myapp -M -R populate_db.py

Anthony
 

On Fri, Aug 28, 2015 at 9:53 AM, Carlos Cesar Caballero Díaz <desar...@spicm.cfg.sld.cu> wrote:
Hi, I need to add some users, and some fields to tables at the first time that my app runs, right now I ask for fields in the tables and if they are empty I put the values, but I don't like to query the tables in all requests for doing this. What do you recommend me?

--
Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/


--
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 web2py+unsubscribe@googlegroups.com.

黄祥

unread,
Aug 28, 2015, 5:54:08 PM8/28/15
to web2py-users
please take a look at this discussion too

best regards,
stifan

Carlos Cesar Caballero Díaz

unread,
Aug 29, 2015, 9:13:19 AM8/29/15
to web...@googlegroups.com
Thank you everyone for your answers, I'm going to use the variable approach and putting it in the .ini config file. Thanks again!!!


El 28/08/15 a las 17:54, 黄祥 escribió:
--
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 web2py+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages