note that db.commit() is needed only in shell or external modules. 

Under web2py environment it is implícit executed. 

It can be simplified as:

[db.tag.insert(name=t) for t in TAGS if not db(db.tag).count()]

(guess it works, not tested)



Em 10/02/2011, às 22:41, Vinicius Assef <[email protected]> escreveu:

> Try  something like this: http://pastebin.com/6yWksPAU
> 
> 
> On Thu, Feb 10, 2011 at 9:36 PM, Marin Pranjic <[email protected]> 
> wrote:
>> Add this after define_table
>> for t in TAGS:
>> ... db.tag.insert(name = t)
>> 
>> run once and then comment / delete the lines.
>> 
>> On Thu, Feb 10, 2011 at 10:57 PM, Sascha Peilicke <[email protected]> wrote:
>>> 
>>> Hi guys,
>>> 
>>> I'd like to know how to best populate a table with a given set of default
>>> values. I could add them manually via the shell, but I'd like it to be
>>> done
>>> when the table is created. Let's consider the following table:
>>> 
>>> db.define_table('tag',
>>>    Field('name'),
>>>    format='%(name)s')
>>> 
>>> And assume I got some tags:
>>> 
>>> TAGS = ['nice','great','awesome']
>>> 
>>> So, how's the most appropriate way in getting those tags into the table?
>>> --
>>> Mit freundlichen Grüßen,
>>> Sascha Peilicke
>>> http://saschpe.wordpress.com
>> 
>> 

Reply via email to