I'm just learning TurboGears and I'm relatively new to Python but
learning the language fast.  My past experience is advanced level ASP
+ SQL Server so I understand server side web development.  I'm running
on Windows Vista.

I've got everything running, thanks to a friend at a user group, but
now I'm on my own and trying to figure a few things out.  I've learned
to use the toolbox in tg-admin for creating models and adding data,
but I have a few questions:

1.) How do I write a simple script to add default data into the
database? Here's what I'm trying but I keep getting an error saying
'Make' is not defined on the last line (if any of this is braindead,
please remember I'm a newbie in this environment):

imcdb= 'C:\Users\mikes\Desktop\Python\imcdb'
imcdb_model= imcdb + '\imcdb'
from sqlobject import *
import sys, os
if imcdb_model not in sys.path:
   sys.path.insert(0,imcdb_model)
import model
sqlhub.processConnection = connectionForURI('sqlite:///' + imcdb +
'\devdata.sqllite')
m= Make()  # ERROR HERE

BTW, here's my current model.py (and if you see anything I'm doing
foolish here, please let me know):

from datetime import datetime
from turbogears.database import PackageHub
from sqlobject import *
from turbogears import identity

hub = PackageHub("imcdb")
__connection__ = hub

class Make(SQLObject):
    class sqlmeta:
        table ='make'
        idName ='id'
    name = StringCol(length=50,varchar=True,unique=True,notNone=True)
    models = MultipleJoin("Model",joinColumn='make_id')

class Model(SQLObject):
    class sqlmeta:
        table ='model'
        idName ='id'
    name = StringCol(length=50,varchar=True,unique=True,notNone=True)
    make = ForeignKey("Make")
    years = MultipleJoin("ModelYear",joinColumn='model_id')

class Year(SQLObject):
    class sqlmeta:
        table ='year'
        idName ='id'
    name = StringCol(length=4,varchar=False,unique=True,notNone=True)
    models = MultipleJoin("ModelYear",joinColumn='year_id')

class ModelYear(SQLObject):
    class sqlmeta:
        table ='model_year'
        idName ='id'
    name = StringCol(length=50,varchar=True,unique=True,notNone=True)
    year = ForeignKey("Year")
    model = ForeignKey("Model")

2.) What's the best practice for doing this longer term?

Thanks in advance.

-Mike


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to