diff options
author | Luke Macken <lmacken@redhat.com> | 2008-06-27 22:59:30 -0400 |
---|---|---|
committer | Luke Macken <lmacken@redhat.com> | 2008-06-27 22:59:30 -0400 |
commit | 5b30509db844bffffbeb61702bbc6917cb2b1170 (patch) | |
tree | 2a3c687c0b656b4a98d7aec20d2ea9841510e6c6 /manas | |
parent | 0cd53a74a183c57b950f636f0da1917ad2a844de (diff) | |
download | manas-5b30509db844bffffbeb61702bbc6917cb2b1170.tar.gz manas-5b30509db844bffffbeb61702bbc6917cb2b1170.tar.xz manas-5b30509db844bffffbeb61702bbc6917cb2b1170.zip |
Add our initial model
Diffstat (limited to 'manas')
-rw-r--r-- | manas/model/__init__.py | 4 | ||||
-rw-r--r-- | manas/model/model.py | 77 |
2 files changed, 79 insertions, 2 deletions
diff --git a/manas/model/__init__.py b/manas/model/__init__.py index f98adc6..933bc15 100644 --- a/manas/model/__init__.py +++ b/manas/model/__init__.py @@ -39,7 +39,7 @@ def init_model(engine): #mapper(Reflected, t_reflected) # Import your model modules here. -from identity import User, Group, Permission +from identity import User, Group, Permission from identity import users_table, groups_table, permissions_table, \ user_group_table, group_permission_table - +from model import Idea, Comment, Tag, Question diff --git a/manas/model/model.py b/manas/model/model.py new file mode 100644 index 0000000..9a0fabb --- /dev/null +++ b/manas/model/model.py @@ -0,0 +1,77 @@ +from pylons import config +from sqlalchemy import * +from sqlalchemy.types import * +from sqlalchemy.orm import mapper, relation +from manas.model import metadata + +idea_table = Table("idea", metadata, + Column("id", Integer, primary_key=True), + Column("title", UnicodeText, unique=True), + Column("timestamp", DateTime, nullable=False, default=func.now()), + Column("author", UnicodeText, nullable=False), + Column("description", UnicodeText, nullable=False), + Column("karma", Integer, default=0)) + +comment_table = Table("comment", metadata, + Column("id", Integer, primary_key=True), + Column("author", UnicodeText, nullable=False), + Column("timestamp", DateTime, nullable=False, default=func.now()), + Column("text", UnicodeText, nullable=False), + Column("idea_id", Integer, ForeignKey('idea.id')), + Column("question_id", Integer, ForeignKey('question.id'))) + +tag_table = Table("tag", metadata, + Column("id", Integer, primary_key=True), + Column("name", UnicodeText, nullable=False, unique=True)) + +idea_tags = Table('idea_tags', metadata, + Column('idea_id', Integer, ForeignKey('idea.id')), + Column('tag_id', Integer, ForeignKey('tag.id'))) + +question_table = Table("question", metadata, + Column("id", Integer, primary_key=True), + Column("title", UnicodeText, unique=True), + Column("timestamp", DateTime, nullable=False, default=func.now()), + Column("author", UnicodeText, nullable=False), + Column("description", UnicodeText, nullable=False), + Column("karma", Integer, default=0)) + +question_tags = Table('question_tags', metadata, + Column('question_id', Integer, ForeignKey('question.id')), + Column('tag_id', Integer, ForeignKey('tag.id'))) + + +class Idea(object): + def __init__(self, **kw): + """automatically mapping attributes""" + for key, value in kw.iteritems(): + setattr(self, key, value) + +class Comment(object): + def __init__(self, **kw): + """automatically mapping attributes""" + for key, value in kw.iteritems(): + setattr(self, key, value) + +class Tag(object): + def __init__(self, **kw): + """automatically mapping attributes""" + for key, value in kw.iteritems(): + setattr(self, key, value) + +class Question(object): + def __init__(self, **kw): + """automatically mapping attributes""" + for key, value in kw.iteritems(): + setattr(self, key, value) + +mapper(Idea, idea_table, properties={ + 'comments': relation(Comment, backref='idea'), + 'tags': relation(Tag, secondary=idea_tags), +}) +mapper(Question, question_table, properties={ + 'comments': relation(Comment, backref='question'), + 'tags': relation(Tag, secondary=question_tags), +}) +mapper(Comment, comment_table) +mapper(Tag, tag_table) |