You can use a .CSV file. What i have used to do is:
1.- Define the tables that are being pre-populate.
2.- Insert all the data with appadmin.
3.- Using the appadmin export the data to a .CSV (db_colors.csv) file
and put it in the private folder of your app.
4.- Do the same thing you are doing except for:
db.color.import_from_csv_file(
open(os.path.join(request.folder, os.path.join('private',
'db_colors.csv')), 'r')
)
5.- done.
2016-08-30 9:34 GMT-04:00 Ben Lawrence <[email protected]>:
> At the moment to pre-populate a database, I place this in the db.py model
> file:
>
> db.define_table('color',
> Field('name','string'),
> Field('code','string'),
> format='%(name)s')
> if db(db.color).isempty():
> # create instance of table
> for k,v in
> dict(lime="#00FF00",red="#FF0000",black="#000000",orange="#FFA500",\
> blue="#0000FF", yellow="#FFFF00", fuchsia="#FF00FF",
> aqua="#00FFFF",\
> maroon="#800000", green="#008000", navy="#000080", olive="#808000",\
> purple="#800080", teal="#008080", gray="#808080",
> silver="#C0C0C0").items():
> db.color.insert(name=k,code=v)
>
>
>
> I wonder if this is the best way to pre-populate a database?
>
> thanks,
> Ben
>
> --
> 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.
--
Yoel Benítez Fonseca
http://redevil.cubava.cu/
$ python -c "import this"
--
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.