def create(self, request): ''' create a story Sample: POST /api/storys/ { title: 'xxx', author: 'houks', text: 'aaaaaaaa', img_url: 'www.a.com/a.png', //optional img_horizontal: 'l', //optional img_veritcal: 't' //optional } } ''' GET = self.flatten_dict(request.GET) POST = self.flatten_dict(request.POST) #pdb.set_trace(); if ('title' not in POST) or \ ('author' not in POST) or \ ('text' not in POST): return rc.BAD_REQUEST title = POST['title'] author = POST['author'] text = POST['text'] #print 'now time' + datetime.datetime.now() new_story = Story(title=title, author=author, text=text) if 'img_url' in POST: new_story.img_url = POST['img_url'] if 'img_vertical' in POST: new_story.img_horizontal = POST['img_veritcal'] if 'img_horizontal' in POST: new_story.img_horizontal = POST['img_horizontal'] new_story.save() return [new_story]