-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPost.py
More file actions
37 lines (30 loc) · 794 Bytes
/
Copy pathPost.py
File metadata and controls
37 lines (30 loc) · 794 Bytes
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
from google.appengine.ext import ndb
import string
import logging
class Post(ndb.Model):
title = ndb.StringProperty(required=True)
content = ndb.StringProperty(required=True, indexed=False)
date = ndb.DateTimeProperty(auto_now_add=True)
def SavePost(key, title, content):
logging.info("#############"+key)
if key is None or key=="":
post = Post()
post.title=title
post.content=content
post.put()
else:
post_key = ndb.Key(Post, string.atol(key))
post=post_key.get()
post.title=title
post.content=content
post.put()
def Delete(key):
post_key = ndb.Key(Post, string.atol(key))
post_key.delete()
def Get(key):
post_key = ndb.Key(Post, string.atol(key))
post=post_key.get()
return post
def List():
posts=Post.query().order(-Post.date)
return posts