【发布时间】:2016-09-17 23:36:41
【问题描述】:
嗯,通常,当我喜欢编辑一个对象时,我会使用实例和 get_object_or_404,如下所示:
question = get_object_or_404(Question, id = id)
form = FormQuestion(request.POST, instance=question)
if request.method == 'POST':
if form.is_valid():
form.save()
return redirect('/Something/')
else:
form = FormQuestion(instance = question)
return render(request, {'form':form}, 'Ask/question.html')
使用此代码我可以编辑一个对象,问题是:我需要列出所有问题并且字段将是可编辑的,但我找不到这样做的方法。
有人有解决我问题的方法或代码吗?
【问题讨论】:
-
是的,Django 支持这个,看Formsets docs.djangoproject.com/en/1.10/topics/forms/formsets