Using @driscollis "Creating GUI Applications with wxPython Chapter 5, I would like to add data into a blank database within the model. This is a first start to understand the ORM mapping. I would like to do this using a csv file for a much larger data set. For another day.
Here is are the classes in model.py
class OlvBook(object):
"""
Book model for ObjectListView
"""
def __init__(self, id, title, author, isbn, publisher,
last_name, first_name):
self.id = id # unique row id from database
self.title = title
self.author = author
self.isbn = isbn
self.publisher = publisher
self.last_name = last_name
self.first_name = first_name
class Person(Base):
""""""
__tablename__ = "people"
id = Column(Integer, primary_key=True)
first_name = Column("first_name", String(50))
last_name = Column("last_name", String(50))
def __repr__(self):
""""""
return "<Person: %s %s>" % (self.first_name, self.last_name)
class Book(Base):
""""""
__tablename__ = "books"
id = Column(Integer, primary_key=True)
author_id = Column(Integer, ForeignKey("people.id"))
title = Column("title", Unicode)
isbn = Column("isbn", Unicode)
publisher = Column("publisher", Unicode)
person = relation("Person", backref="books", cascade_backrefs=False)
# Create the database if not already created
metadata.create_all(engine)
Here’s the data I would like to add to the tables using @driscollis book as my example.
Session = sessionmaker(bind=engine)
session = Session()
# Add data to the tables
personOne = Person("John", "Smith")
personOne.book1 = Book("Johns's Book", "Book Title", 123456, "Book Publisher")
session.add(personOne)
session.add(personOne)
session.commit()
Here is the Traceback
File "g:\Projects\Python\GUI\wxPython\DB_Editor\model.py", line 83, in <module>
personOne = Person("John", "Smith")
TypeError: __init__() takes 1 positional argument but 3 were given
Where does the 1 positional argument come from? Line 83 isolated below.
personOne = Person("John", "Smith")