本文整理汇总了Python中models.Todo.save方法的典型用法代码示例。如果您正苦于以下问题:Python Todo.save方法的具体用法?Python Todo.save怎么用?Python Todo.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Todo
的用法示例。
在下文中一共展示了Todo.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: from models import Todo [as 别名]
# 或者: from models.Todo import save [as 别名]
def add():
form = TodoForm(request.form)
if form.validate():
content = form.content.data
todo = Todo(content=content, time=datetime.now())
todo.save()
return redirect(url_for('index'))
示例2: addtodo
# 需要导入模块: from models import Todo [as 别名]
# 或者: from models.Todo import save [as 别名]
def addtodo(request):
if 'Item' in request.GET and request.GET['Item']:
newname = request.GET['Item']
newstatue = '0'
# print('1')
newid = Todo.objects.order_by('id').reverse()[0].id+1
todo = Todo(id=newid, name=newname, statue=newstatue)
todo.save()
# NOtE:重定向至首页,安全一些
return HttpResponseRedirect('/index/')
##or:发送请求至首页与重定向有区别
# return index(request)
# notlist = Todo.objects.filter(statue=0)
# finishlist = Todo.objects.filter(statue=1)
# notpaginator = Paginator(notlist, 3)
# finishpaginator = Paginator(finishlist, 3)
# try:
# anotpage = int(request.GET.get('notpage', 1))
# afinishpage = int(request.GET.get('finishpage', 1))
# nottodo = notpaginator.page(anotpage)
# finish = finishpaginator.page(afinishpage)
# # print(Todo.objects.order_by('id').reverse()[0].id + 1)
# except (EmptyPage, InvalidPage, PageNotAnInteger):
# nottodo = notpaginator.page(1)
# finish = finishpaginator.page(1)
# return render_to_response('index.html',
# {'nottodo': nottodo, 'finish': finish},
# context_instance=RequestContext(request))
else:
return HttpResponseRedirect('/index/')
示例3: add_todo
# 需要导入模块: from models import Todo [as 别名]
# 或者: from models.Todo import save [as 别名]
def add_todo():
"""Add a todo."""
form = TodoForm()
if request.method == 'POST' and form.validate_on_submit():
todo = Todo(text=form.todo.data)
todo.save()
return redirect(url_for('todo_list'))
示例4: add
# 需要导入模块: from models import Todo [as 别名]
# 或者: from models.Todo import save [as 别名]
def add():
form = TodoForm(request.form)
if form.validate():
content = form.content.data
todo = Todo(content=content)
todo.save()
todos = Todo.objects.all()
return render_template("index.html", todos=todos, form=form)
示例5: add
# 需要导入模块: from models import Todo [as 别名]
# 或者: from models.Todo import save [as 别名]
def add():
form = request.form
content = form['content']
todo = Todo(content = content)
todo.save()
todos = Todo.objects.all()
return render_template("index.html",todos)
示例6: add
# 需要导入模块: from models import Todo [as 别名]
# 或者: from models.Todo import save [as 别名]
def add():
content = request.form.get("content")
status = request.form.get("status")
todo = Todo(content=content, status=status)
todo.save()
# return redirect("/")
todos = Todo.objects.all()
return render_template("index.html", todos=todos)
示例7: submit_word
# 需要导入模块: from models import Todo [as 别名]
# 或者: from models.Todo import save [as 别名]
def submit_word(user_id):
"""Add a todo."""
form = TodoForm()
if request.method == 'POST' and form.validate_on_submit():
todo = Todo(text=form.todo.data)
todo.save()
return redirect(url_for('game_list'))
示例8: add
# 需要导入模块: from models import Todo [as 别名]
# 或者: from models.Todo import save [as 别名]
def add():
form = TodoForm(request.form)
if form.validate():
content = form.content.data
todo = Todo(content=content,time=datetime.now())
todo.save()
todos = Todo.objects.order_by('-time')
return render_template("index.html",todos=todos,form=form)
示例9: addTodo
# 需要导入模块: from models import Todo [as 别名]
# 或者: from models.Todo import save [as 别名]
def addTodo(request):
todoText = request.GET.get('item')
todo = Todo(text = todoText)
todo.save()
return render_to_response('dashboard/todo.html', {'todoItem':todo}, context_instance =RequestContext(request))
示例10: add
# 需要导入模块: from models import Todo [as 别名]
# 或者: from models.Todo import save [as 别名]
def add():
form = TodoForm(request.form)
if form.validate():
content = form.content.data
todo = Todo(content = content)
todo.save()
# Show all the list again
todos = Todo.objects.order_by('-time')
return render_template("index.html", todos = todos, form = form)
示例11: add
# 需要导入模块: from models import Todo [as 别名]
# 或者: from models.Todo import save [as 别名]
def add(request):
if request.method =='POST':
try:
action = request['action']
print 'action is:', action
except:
return HttpResponseRedirect('/')
item = Todo(action=action, status=False, user=request.user)
item.save()
return HttpResponseRedirect('/')
示例12: addtodo
# 需要导入模块: from models import Todo [as 别名]
# 或者: from models.Todo import save [as 别名]
def addtodo(request):
if request.method == 'POST':
todo = request.POST['todo']
priority = request.POST['priority']
user = User.objects.get(id=1)
addtodo = Todo(user=user, todo=todo, priority=priority, flag='1')
addtodo.save()
todolist = Todo.objects.filter(flag=1)
finishtodos = Todo.objects.filter(flag=0)
return HttpResponseRedirect("/todolists/")
示例13: testAlterTodo
# 需要导入模块: from models import Todo [as 别名]
# 或者: from models.Todo import save [as 别名]
def testAlterTodo(self):
todo = Todo()
todo.text = "Get some milk"
todo.timestamp = datetime.now()
todo.save()
assert not todo.completed
todo.completed = True
todo.save()
assert todo.completed
示例14: add_todo
# 需要导入模块: from models import Todo [as 别名]
# 或者: from models.Todo import save [as 别名]
def add_todo(request):
t = Todo( # Creates new todo
title = request.POST['title'],
description = request.POST['description'],
importance = request.POST['importance'],
start_date = request.POST['start_date'],
stop_date = request.POST['stop_date'],
owner = request.user)
t.save()
# reverse() takes etiher a view or the name of a view and returns its URLS:
return HttpResponseRedirect(reverse(todo_index)) # Redirect todo_index view
示例15: create
# 需要导入模块: from models import Todo [as 别名]
# 或者: from models.Todo import save [as 别名]
def create(request):
req = simplejson.loads(request.raw_post_data)
content = req['content']
order = req['order']
if not content:
return HttpResponse(simplejson.dumps({'success':False}), mimetype = 'application/json')
todo = Todo()
todo.content = content
todo.order = order
todo.save()
return HttpResponse(simplejson.dumps({'success':True}), mimetype = 'application/json')