-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
59 lines (47 loc) · 1.51 KB
/
models.py
File metadata and controls
59 lines (47 loc) · 1.51 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from google.appengine.ext import ndb
from google.appengine.api import taskqueue
from webapp2_extras.appengine.auth import models as webappmodels
class User(webappmodels.User):
last_fetched = ndb.DateTimeProperty()
author = ndb.StringProperty()
def delete(self):
ndb.delete_multi(ndb.Query(ancestor=self.key).iter(keys_only=True))
webappmodels.Unique.delete_multi(
map(lambda s: 'User.auth_id:' + s, self.auth_ids)
)
@property
def pages(self):
return Page.query(ancestor=self.key)
class Page(ndb.Model):
name = ndb.StringProperty()
access_token = ndb.StringProperty()
last_fetched = ndb.DateTimeProperty()
@property
def authors(self):
return [post.author for post in Post.query(
ancestor=self.key,
projection=['author'],
distinct=True
) if post.author != None]
@property
def posts(self):
return Post\
.query(ancestor=self.key)\
.order(-Post.created_time)\
.filter(Post.is_reply == False)
class Post(ndb.Model):
is_reply = ndb.BooleanProperty(indexed=True, default=False)
is_private = ndb.BooleanProperty(default=False)
message = ndb.TextProperty()
created_time = ndb.DateTimeProperty()
updated_time = ndb.DateTimeProperty()
from_id = ndb.StringProperty()
from_name = ndb.StringProperty()
from_category = ndb.StringProperty()
author = ndb.StringProperty(indexed=True)
@property
def replies(self):
return Post\
.query(ancestor=self.key)\
.filter(Post.is_reply == True)\
.order(Post.created_time)