本文整理汇总了Python中survey.models.Survey.save_sample_size方法的典型用法代码示例。如果您正苦于以下问题:Python Survey.save_sample_size方法的具体用法?Python Survey.save_sample_size怎么用?Python Survey.save_sample_size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类survey.models.Survey
的用法示例。
在下文中一共展示了Survey.save_sample_size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit
# 需要导入模块: from survey.models import Survey [as 别名]
# 或者: from survey.models.Survey import save_sample_size [as 别名]
def edit(request, survey_id):
try:
survey = Survey.objects.get(id=survey_id)
survey_form = SurveyForm(instance=survey)
if request.method == 'POST':
survey_form = SurveyForm(instance=survey, data=request.POST)
if survey_form.is_valid():
Survey.save_sample_size(survey_form)
messages.success(request, 'Survey successfully edited.')
return HttpResponseRedirect(reverse('survey_list_page'))
elif survey_form.errors.get('__all__'):
messages.error(request, survey_form.errors['__all__'])
context = {'survey_form': survey_form,
'title': "Edit Survey",
'button_label': 'Save',
'id': 'edit-survey-form',
'cancel_url': request.META.get('HTTP_REFERER') or reverse('survey_list_page'),
'action': reverse('edit_survey_page', args=(survey_id, ))
}
request.breadcrumbs([
('Surveys', reverse('survey_list_page')),
])
return render(request, 'surveys/new.html', context)
except Survey.DoesNotExist:
messages.error(request, 'survey does not exists')
return HttpResponseRedirect(reverse('survey_list_page'))
示例2: new
# 需要导入模块: from survey.models import Survey [as 别名]
# 或者: from survey.models.Survey import save_sample_size [as 别名]
def new(request):
response = None
survey_form = SurveyForm()
if request.method == 'POST':
survey_form = SurveyForm(request.POST)
if survey_form.is_valid():
Survey.save_sample_size(survey_form)
messages.success(request, 'Survey successfully added.')
response = HttpResponseRedirect(reverse('survey_list_page') )
elif survey_form.errors.get('__all__'):
messages.error(request, survey_form.errors['__all__'])
context = {'survey_form': survey_form,
'title': "New Survey",
'button_label': 'Create',
'id': 'add-survey-form',
'action': ".",
'cancel_url': request.META.get('HTTP_REFERER') or reverse('survey_list_page'),
}
request.breadcrumbs([
('Surveys', reverse('survey_list_page')),
])
return response or render(request, 'surveys/new.html', context)