Added tables and models for files and media types.

This commit is contained in:
Raoul Snyman 2010-04-14 08:32:38 +02:00
parent 705a88c54d
commit ff0e6e0093
3 changed files with 51 additions and 10 deletions

View File

@ -28,11 +28,12 @@ from sqlalchemy.orm import mapper, relation, backref
from scribeengine.model import meta
from scribeengine.model.tables import categories_table, comments_table, \
pages_table, permissions_table, posts_table, roles_table, tags_table, \
users_table, variables_table, categories_posts_table, \
permissions_roles_table, posts_tags_table, roles_users_table
from scribeengine.model.classes import Category, Comment, Page, Permission, \
Post, Role, Tag, User, Variable
files_table, media_types_table, pages_table, permissions_table, \
posts_table, roles_table, tags_table, users_table, variables_table, \
categories_posts_table, permissions_roles_table, posts_tags_table, \
roles_users_table
from scribeengine.model.classes import Category, Comment, File, MediaType, \
Page, Permission, Post, Role, Tag, User, Variable
def init_model(engine):
"""Call me before using any of the tables or classes in the model"""
@ -41,25 +42,36 @@ def init_model(engine):
mapper(Category, categories_table)
mapper(Comment, comments_table)
mapper(File, files_table)
mapper(MediaType, media_types_table,
properties={
u'files': relation(File, backref=u'media_type')
}
)
mapper(Page, pages_table)
mapper(Permission, permissions_table)
mapper(Post, posts_table,
properties={
u'categories': relation(Category, backref='posts', secondary=categories_posts_table),
u'comments': relation(Comment, backref=u'post', order_by=Comment.created.asc()),
u'tags': relation(Tag, backref=backref(u'posts', order_by='posts.created DESC'), secondary=posts_tags_table)
u'categories': relation(Category, backref=u'posts',
secondary=categories_posts_table),
u'comments': relation(Comment, backref=u'post',
order_by=Comment.created.asc()),
u'tags': relation(Tag,
backref=backref(u'posts', order_by='posts.created DESC'),
secondary=posts_tags_table)
}
)
mapper(Role, roles_table,
properties={
u'permissions': relation(Permission, backref=u'roles', secondary=permissions_roles_table)
u'permissions': relation(Permission, backref=u'roles',
secondary=permissions_roles_table)
}
)
mapper(Tag, tags_table)
mapper(User, users_table,
properties={
u'comments': relation(Comment, backref=u'user'),
#u'pages': relation(Page, backref=u'user'),
u'files': relation(File, backref=u'user'),
u'posts': relation(Post, backref=u'user'),
u'roles': relation(Role, backref=u'users', secondary=roles_users_table)
}

View File

@ -55,6 +55,20 @@ class Comment(BaseModel):
pass
class File(BaseModel):
"""
A file in the media library.
"""
pass
class MediaType(BaseModel):
"""
Distinguishes between different types of media.
"""
pass
class Page(BaseModel):
"""
A page on the blog. This is separate from a blog entry, for things like

View File

@ -50,6 +50,21 @@ comments_table = Table(u'comments', metadata,
Column(u'modified', DateTime, default=datetime.now())
)
files_table = Table(u'files', metadata,
Column(u'id', Integer, primary_key=True),
Column(u'user_id', Integer, ForeignKey(u'users.id'), nullable=False),
Column(u'media_type_id', Integer, ForeignKey(u'media_types.id'), nullable=False),
Column(u'filename', Unicode(255), nullable=False, index=True),
Column(u'mimetype', Unicode(255)),
Column(u'path', Unicode(255)),
Column(u'size', Integer, default=0)
)
media_types_table = Table(u'media_types', metadata,
Column(u'id', Integer, primary_key=True),
Column(u'title', Unicode(255), nullable=False, index=True)
)
# Definition of the "pages" table
pages_table = Table(u'pages', metadata,
Column(u'id', Integer, primary_key=True),