I'm giving TG2 (1.9.7a3) a whirl in a virtualenv after doing some
stuff with TG1 a few months ago. Building my data model and trying to
initialize the db as per the wiki example at
http://www.turbogears.org/2.0/docs/main/Wiki20/wiki20.html#initializing-the-tables,
I get the following TraceBack:
Traceback (most recent call last):
File "initialize_db.py", line 13, in <module>
advice = Advice("Don't eat raw chicken.")
TypeError: __init__() takes exactly 1 argument (2 given)
The code in my initialize_db.py:
from mytestproject.model import DBSession, Advice, metadata
from sqlalchemy import create_engine
# Prepare the database connection
engine = create_engine("postgres://...", echo=True)
DBSession.configure(bind=engine)
# Create the tables
metadata.drop_all(engine)
metadata.create_all(engine)
# Create an object and set some data
advice = Advice("Don't eat raw chicken.")
# Save the object to the in memory DBSession
DBSession.save(advice)
# Use commit() to write all in-memory changes to the database.
DBSession.commit()
The relevant definition from my data model:
advice_table = Table('advice', metadata,
Column('advice_id', Integer, primary_key=True),
Column('text', Unicode(255))
)
class Advice(object):
"""Just what the doctor ordered.
"""
def __init__(self, text):
self.text = text
def __repr__(self):
return '<Advice: text=%s>' % self.text
DBSession.mapper(Advice, advice_table)
If I instead do it like this in initialize_db.py:
advice = Advice()
advice.text = "Don't eat raw chicken."
it works and is committed to the database. If I fire up an interactive
Python shell and import my model, the first form works (i.e.
Advice("Foo") works as intended). What am I doing wrong?
\\kristian
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---