本文整理汇总了Python中models.SpeakerForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python SpeakerForm.is_valid方法的具体用法?Python SpeakerForm.is_valid怎么用?Python SpeakerForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.SpeakerForm
的用法示例。
在下文中一共展示了SpeakerForm.is_valid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sample_form
# 需要导入模块: from models import SpeakerForm [as 别名]
# 或者: from models.SpeakerForm import is_valid [as 别名]
def sample_form(request):
if request.method == 'POST':
sf = None
instance_id = request.GET.get(u'speaker')
if instance_id is not None:
instance = get_object_or_404(Speaker, pk=instance_id)
sf = SpeakerForm(request.POST, instance=instance)
else:
sf = SpeakerForm(request.POST)
if sf.is_valid():
speaker = sf.save()
return http.HttpResponseRedirect(reverse("sampleformok", args=[speaker.pk]))
else:
return render_to_response('test/form.html', {'form': sf}, context_instance=RequestContext(request))
elif request.method == 'GET':
form = None
instance_id = request.GET.get(u'speaker')
if instance_id is not None:
instance = get_object_or_404(Speaker, pk=instance_id)
form = SpeakerForm(instance=instance)
else:
form = SpeakerForm(initial={u'languages': [1, 2], u'group': 1})
return render_to_response('test/form.html', {'form': form}, context_instance=RequestContext(request))
else:
return http.HttpResponseNotAllowed(['GET', 'POST'])