Krys Wilken wrote:
> I think both ideas are of value. An exec command for running scripts,
> and a special module-level function in model.py that is run
> automatically by sql create.
I might like it, too. What do you think of this:
Index: turbogears/quickstart/projectname/model.py.source
===================================================================
--- turbogears/quickstart/projectname/model.py.source (Revision 43)
+++ turbogears/quickstart/projectname/model.py.source (Arbeitskopie)
@@ -6,3 +6,6 @@
# class YourDataClass(SQLObject):
# pass
+
+# def tg_init_database():
+# pass
Index: turbogears/command/__init__.py
===================================================================
--- turbogears/command/__init__.py (Revision 43)
+++ turbogears/command/__init__.py (Arbeitskopie)
@@ -104,6 +104,12 @@
from sqlobject.manager import command
command.the_runner.run(sys.argv)
+ if sqlobjcommand == "create":
+ mod = self.get_model()
+ if hasattr(mod, 'tg_init_database'):
+ print 'Filling database'
+ mod.tg_init_database()
+
def fix_egginfo(self, eggname):
print """
Two issues with that:
1. This behaviour may be unexpected by people who are familiar with
"sqlobject-admin create".
2. If you run "sql create" twice or more, those init values are doubled.
> An alternative to a single module-level function would be a special
> method on each model that is responsible for populating itself, perhaps
> "post_create(self)" or something. Sql create could just call that
> method of each model after all the tables have been created.
I don't think this granularity is useful, as you can only create all
models at once (I think).
Fabian