Permalink
Browse files

Split models into separate files

  • Loading branch information...
1 parent 49bb327 commit c9628c1bc7eb8695b46f98adae28b1d6f6d9cf78 @rhaamo committed Jan 11, 2014
View
6 codular/__init__.py
@@ -1,11 +1,7 @@
from pyramid.config import Configurator
from sqlalchemy import engine_from_config
-from .models import (
- DBSession,
- Base,
- )
-
+from .models.meta import (DBSession, Base)
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
View
27 codular/models.py
@@ -1,27 +0,0 @@
-from sqlalchemy import (
- Column,
- Index,
- Integer,
- Text,
- )
-
-from sqlalchemy.ext.declarative import declarative_base
-
-from sqlalchemy.orm import (
- scoped_session,
- sessionmaker,
- )
-
-from zope.sqlalchemy import ZopeTransactionExtension
-
-DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
-Base = declarative_base()
-
-
-class MyModel(Base):
- __tablename__ = 'models'
- id = Column(Integer, primary_key=True)
- name = Column(Text)
- value = Column(Integer)
-
-Index('my_index', MyModel.name, unique=True, mysql_length=255)
View
4 codular/models/__init__.py
@@ -0,0 +1,4 @@
+# Package
+
+from .meta import DBSession
+from .user import MyModel
View
11 codular/models/meta.py
@@ -0,0 +1,11 @@
+from sqlalchemy.ext.declarative import declarative_base
+
+from sqlalchemy.orm import (
+ scoped_session,
+ sessionmaker,
+ )
+
+from zope.sqlalchemy import ZopeTransactionExtension
+
+DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
+Base = declarative_base()
View
16 codular/models/user.py
@@ -0,0 +1,16 @@
+from .meta import Base
+
+from sqlalchemy import (
+ Column,
+ Index,
+ Integer,
+ Text,
+ )
+
+class MyModel(Base):
+ __tablename__ = 'models'
+ id = Column(Integer, primary_key=True)
+ name = Column(Text)
+ value = Column(Integer)
+
+Index('my_index', MyModel.name, unique=True, mysql_length=255)
View
7 codular/scripts/initializedb.py
@@ -11,11 +11,8 @@
from pyramid.scripts.common import parse_vars
-from ..models import (
- DBSession,
- MyModel,
- Base,
- )
+from ..models.meta import (DBSession, Base)
+from ..models import MyModel
def usage(argv):
View
2 codular/templates/home.jinja2
@@ -1,6 +1,6 @@
{% extends "layout.jinja2" %}
{% block content %}
<p>
- Home page
+ Home page {{ one }}
</p>
{% endblock %}

0 comments on commit c9628c1

Please sign in to comment.