本文整理汇总了Python中models.Note.post_type方法的典型用法代码示例。如果您正苦于以下问题:Python Note.post_type方法的具体用法?Python Note.post_type怎么用?Python Note.post_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Note
的用法示例。
在下文中一共展示了Note.post_type方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_note
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import post_type [as 别名]
def new_note(request):
if request.method == 'GET':
context = {'suppress_menu':True}
return render(request, 'cloud_notes/new.html', context)
elif request.method == 'POST':
if "cancel" in request.POST:
return redirect('cloud_notes.views.list')
else:
form = NoteForm(request.POST)
context = {'form':form}
if form.is_valid():
# do stuff
# ...
if 'notes_folder' in request.session:
fldr = Folder.objects.get(pk=request.session['notes_folder'], user=request.user)
else:
fldr = Folder.objects.get(name="Main", user=request.user)
# Don't allow user to inadvertently create note in Trash
if fldr.name == 'Trash':
fldr = Folder.objects.get(name="Main", user=request.user)
obj = Note()
obj.title = form.cleaned_data['title']
obj.note = form.cleaned_data['note']
obj.post_type = 'note'
obj.created_at = datetime.utcnow()
obj.modified_at = datetime.utcnow()
obj.user = request.user
obj.folder = fldr
obj.save()
return redirect('cloud_notes.views.list')
else:
print form.errors
return render(request, 'cloud_notes/new.html', context)