initial version of the sms written at DBA
[rapidsms] / db.py
1 from storm.locals import *
2 database = create_database("mysql:uniphone")
3 store = Store(database)
4
5 class Person(object):
6     __storm_table__ = "people"
7     id = Int(primary=True)
8     name = Unicode()
9     phone_number = Unicode()
10
11     def __init__(self, **kw):
12         self.name = unicode(kw['name'])
13         self.phone_number = unicode(kw['phone_number'])
14
15 class Questionaire(object):
16     __storm_table__ = "questionaires"
17     id = Int(primary=True)
18     code = Unicode()
19     description = Unicode()
20
21     def __init__(self, **kw):
22         self.code = unicode(kw['code'])
23         self.description = unicode(kw['description'])
24
25 class Question(object):
26     __storm_table__ = "questions"
27     id = Int(primary=True)
28     code = Unicode()
29     longdesc = Unicode()
30     shortdesc = Unicode()
31     datatype = Unicode()
32     questionaire_id = Int()
33     questionaire = Reference(questionaire_id, Questionaire.id)
34
35     def __init__(self, **kw):
36         self.code = unicode(kw['code'])
37         self.longdesc = unicode(kw['longdesc'])
38         self.shortdesc = unicode(kw['shortdesc'])
39         self.datatype = unicode(kw['datatype'])
40         self.questionaire_id = int(kw['questionaire_id'])
41
42 class Answer(object):
43     __storm_table__ = "answers"
44     id = Int(primary=True)
45     answer = Unicode()
46     received = DateTime()
47     question_id = Int()
48     question = Reference(question_id, Question.id)
49     people_id = Int()
50     person = Reference(people_id, Person.id)
51
52     def __init__(self, **kw):
53         self.answer = unicode(kw['answer'])
54         self.received = unicode(kw['received']) # have this change to the right type
55
56 # define the many to one relationships
57 Person.answers = ReferenceSet(Person.id, Answer.id)
58 Questionaire.questions = ReferenceSet(Questionaire.id, Question.questionaire_id)
59 Question.answers = ReferenceSet(Question.id, Answer.id)
60

Benjamin Mako Hill || Want to submit a patch?