本文整理汇总了Python中models.Entry.serialize方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.serialize方法的具体用法?Python Entry.serialize怎么用?Python Entry.serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Entry
的用法示例。
在下文中一共展示了Entry.serialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_entry
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import serialize [as 别名]
def add_entry(request):
title = json.loads(request.body)['title']
text = json.loads(request.body)['text']
entry = Entry(user=request.user, title=title, text=text)
entry.save()
data = json.dumps(Entry.serialize(entry))
return HttpResponse(data, content_type="application/json")
示例2: post_new_entry
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import serialize [as 别名]
def post_new_entry():
# Make sure that the request actually has content.
if 'content' not in request.json:
return bad_request
content = request.json['content']
# Save to the database and return content for confirmation.
user_id = session['user_id']
new_entry = Entry(user_id, content)
database.db_session.add(new_entry)
database.db_session.commit()
return jsonify({
'entry': new_entry.serialize()
})
示例3: get_entry
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import serialize [as 别名]
def get_entry(request, entry_id):
query = Entry.objects.get(id=entry_id)
data = json.dumps(Entry.serialize(query))
return HttpResponse(data, content_type="application/json")
示例4: get_entries
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import serialize [as 别名]
def get_entries(request):
query = Entry.objects.all().order_by('-created_date');
data = json.dumps([Entry.serialize(entry) for entry in query])
return HttpResponse(data, content_type="application/json")