Permalink
Browse files

init

  • Loading branch information...
0 parents commit d8f21530abe12123fa04f55f5bf276b198374327 @alswl committed Jan 6, 2012
Showing with 134 additions and 0 deletions.
  1. +30 −0 .gitignore
  2. 0 README.asciidoc
  3. +19 −0 contact.py
  4. +18 −0 meta.py
  5. +14 −0 phone.py
  6. +26 −0 sms.py
  7. +27 −0 smsir.py
@@ -0,0 +1,30 @@
+*.py[co]
+
+# Packages
+*.egg
+*.egg-info
+dist
+build
+eggs
+parts
+bin
+var
+sdist
+develop-eggs
+.installed.cfg
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+
+#Translations
+*.mo
+
+#Mr Developer
+.mr.developer.cfg
+
+#myself
+data.db
No changes.
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+# coding=utf8
+
+from sqlalchemy import Column, Integer, String, Unicode
+from sqlalchemy.orm import relationship, backref
+
+from meta import Base, session
+
+class Contact(Base):
+ """contact model"""
+ __tablename__ = 'contact'
+
+ id = Column(Integer, primary_key=True)
+ name = Column(Unicode(50), nullable=False)
+
+ #sms = relationship("Sms", order_by='Sms.id', backref='contact')
+
+ def __init__(self, name):
+ self.name = name
18 meta.py
@@ -0,0 +1,18 @@
+# coding=utf8
+
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.orm import scoped_session, sessionmaker
+from sqlalchemy import create_engine
+
+__all__ = ['Base', 'Session']
+
+#engine = create_engine('sqlite:///:memory:', echo=True)
+engine = create_engine('sqlite:///data.db', echo=True)
+
+# SQLAlchemy session manager. Updated by model.init_model()
+Session = scoped_session(sessionmaker())
+Session.configure(bind=engine)
+session = Session()
+
+# The declarative Base
+Base = declarative_base()
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+# coding=utf8
+
+from sqlalchemy import Column, Integer, String, Unicode
+
+from meta import Base, Session
+
+class Phone(Base):
+ """contact model"""
+ __tablename__ = 'phone'
+
+ id = Column(Integer, primary_key=True)
+ number = Column(String(50), nullable=False)
+
26 sms.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+# coding=utf8
+
+from sqlalchemy import Column, Integer, String
+from sqlalchemy import ForeignKey
+from sqlalchemy.orm import relationship, backref
+
+from meta import Base, session
+
+class Sms(Base):
+ """sms model"""
+ __tablename__ = 'sms'
+
+ id = Column(Integer, primary_key=True)
+ from_contact_id = Column(Integer, ForeignKey('contact.id'))
+ from_contact = relationship('Contact', backref='sms')
+
+ content = Column(String(500))
+ # TODO create_at
+
+ def __init__(self):
+ pass
+
+ def add(self):
+ session.add(self)
+ session.commit()
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+# coding=utf8
+
+from meta import session, Base
+from sms import Sms
+from contact import Contact
+
+class Smsir(object):
+ """A sms helper"""
+
+ def __init__(self, session, Base):
+ self.session = session
+ self.Base = Base
+
+ def create_all(self):
+ Base.metadata.create_all()
+
+ def import_from_xml(self):
+ pass
+
+ def import_from_txt(self):
+ pass
+
+ def test(self):
+ sms = Sms()
+ sms.from_contact = Contact(u'路飞')
+ sms.add()

0 comments on commit d8f2153

Please sign in to comment.