-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord.py
41 lines (34 loc) · 953 Bytes
/
record.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from google.appengine.ext import ndb
from datetime import datetime
class Record(ndb.Model):
"""A model for representing an odd and its image"""
title = ndb.StringProperty()
num = ndb.IntegerProperty()
denom = ndb.IntegerProperty()
category = ndb.StringProperty()
createDate = ndb.DateTimeProperty()
citation = ndb.StringProperty()
def json(self):
j = {
'key': self.key.urlsafe(),
'title': self.title,
'odds': str(self.num) + ':' + str(self.denom),
'citation': self.citation,
'createDate': str(self.createDate)
};
return j
def get_all():
return Record.query()
def get(urlkey):
return ndb.Key(urlsafe=urlkey).get()
def new(title, num, denom, citation):
record = Record()
record.title = title
record.num = num
record.denom = denom
record.citation = citation
record.createDate = datetime.now()
record.put()
return record
def delete(key):
ndb.Key(urlsafe=key).delete()