Turbogears is driving me crazy! I don't remember ever having this
much trouble learning something new. My problem is that I learn by
example, and TG is really failing me. Either the example for what I
want to do doesn't exist, or it's wrong. All I want to do is create
three related tables. The tutorials that show you how to do this are
for TG 1, meaning they use SQLObject and a different syntax. The Wiki
2.0 tutorial doesn't have any related tables; the RestControllers
tutorial does, but it's adding another layer of complexity that I
don't understand and probably don't need.
My three tables are Corpus, Genres, and UploadedFiles. Each item in
the corpus with be one of several genres (one-to-many), and will be
associated with one or more files. (The files will only be associated
with one corpus item, so that's also a one-to-many relationship, but
going the other way.) This seems like it should be very easy to do,
but I haven't been able to find straight-forward instructions on how
to do it. I've wasted days and days, and I really hope you guys can
help me... (I'm very new to TurboGears and pretty new to Python,
also, so speak slowly and use small words...)
This is what I've got so far, and I know I'm missing some vital
pieces:
from sqlalchemy import *
from sqlalchemy.orm import mapper, relation, backref
from sqlalchemy import Table, ForeignKey, Column
from sqlalchemy.types import Integer, Unicode
from tunisiyya.model import DeclarativeBase, metadata, DBSession
class Genres(DeclarativeBase):
__tablename__ = 'genres'
genre_id = Column(Integer, primary_key=True)
name = Column(Text(50))
def __init__(self, name, **kw):
self.name = name
class Corpus(DeclarativeBase):
__tablename__ = 'corpus'
id = Column(Integer, primary_key=True)
title = Column(Unicode, unique=True)
author = Column(Unicode)
genre = Column(Integer, ForeignKey('genres.genre_id'))
pub_date = Column(Date, nullable=True)
def __init__(self, title, author, genre, pub_date, **kw):
self.title = title
self.author = author
self.genre = genre
self.pub_date = pub_date
class UploadedFiles(DeclarativeBase):
__tablename__ = 'uploaded_files'
file_id = Column(Integer, primary_key=True)
filename = Column(Unicode, unique=True)
abspath = Column(Unicode)
size = Column(Integer)
corpus_item = Column(Integer, ForeignKey('corpus.id')
def __init__(self, filename, abspath, size, corpus_item, **kw):
self.filename = filename
self.abspath = abspath
self.size = size
self.corpus_item = corpus_item
--
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.