Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
alswl committed Jan 6, 2012
0 parents commit d8f2153
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .gitignore
@@ -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
Empty file added README.asciidoc
Empty file.
19 changes: 19 additions & 0 deletions contact.py
@@ -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 changes: 18 additions & 0 deletions 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()
14 changes: 14 additions & 0 deletions phone.py
@@ -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 changes: 26 additions & 0 deletions 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()
27 changes: 27 additions & 0 deletions smsir.py
@@ -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.