-
Notifications
You must be signed in to change notification settings - Fork 4
/
models.py
38 lines (31 loc) · 1.04 KB
/
models.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
from google.appengine.ext import ndb
from json_serializer import JSONSerializable
class Article(ndb.Model, JSONSerializable):
title = ndb.StringProperty(indexed=False)
content = ndb.StringProperty(indexed=False)
date = ndb.DateTimeProperty(auto_now_add=True)
@property
def id(self):
return self.key.integer_id()
def toJSON(self):
return {
"id": self.id,
"title": self.title,
"content": self.content
}
class Comment(ndb.Model, JSONSerializable):
article = ndb.KeyProperty(kind=Article, indexed=True)
author_name = ndb.StringProperty(indexed=False)
author_email = ndb.StringProperty(indexed=False)
content = ndb.StringProperty(indexed=False)
date = ndb.DateTimeProperty(auto_now_add=True)
@property
def id(self):
return self.key.integer_id()
def toJSON(self):
return {
"id": self.id,
"author_name": self.author_name,
"author_email": self.author_email,
"content": self.content
}