mysql问卷表设计_调查问卷表结构设计及具体实现

1 from django.core.validators importRegexValidator2 from django.db.models.aggregates importCount3 from django.forms.forms importForm4 from django.http.response importJsonResponse5 from django.shortcuts importrender, HttpResponse,redirect6 from app01 importmodels7 from django.forms importModelForm,fields,widgets8 importjson9 from django.core.exceptions importValidationError10 from django.core.validators importRegexValidator11 #Create your views here.

12 defindex(request):13 Questionnaire_obj =models.Questionnaire.objects.all()14 #查询问卷所属的班级的学生个数

15 for naire inQuestionnaire_obj:16 naire.part_num = models.Answer.objects.filter(queston__in=naire.questions_set.all()).values_list('student_id').distinct().count()17 print(naire.part_num)18 return render(request,"index.html",{"Questionnaire_obj":Questionnaire_obj})19

20 classQuestionForm(ModelForm):21 classMeta:22 model =models.Questions23 fields = ["caption","question_type"]24

25 error_messages ={26 "caption":{"required":"不能为空"}27 }28 widgets ={29 "caption":widgets.Textarea(attrs={"class": "question","rows":0,"cols":0})30 }31

32 classOptionModelForm(ModelForm):33 classMeta:34 model =models.Option35 fields = ["name","score"]36

37 defquestionedit(request,nid):38 #方式一:

39 ##查询当前问卷的所有的问题

40 #que_list = models.Questions.objects.filter(questionnaire_id=nid).all()

41 #question_list = []

42 #if not que_list:

43 #'''新建的问题,还没有创建问题'''

44 #form = QuestionForm()

45 #question_list.append(form)

46 #return render(request,"questionedit.html",{"question_list":question_list})

47 #else:

48 #'''已经创建了问题的'''

49 #for que in que_list:

50 #print(que,"que===")

51 #form = QuestionForm(instance=que)

52 #question_list.append(form)

53 #return render(request,"questionedit.html",{"question_list":question_list})

54

55 #方式二:

56 #查询当前问卷的所有的问题

57 #def inner():

58 #que_list = models.Questions.objects.filter(questionnaire_id=nid).all()

59 #if not que_list:

60 #'''新建的问题,还没有创建问题'''

61 #form = QuestionForm()

62 #yield form

63 #else:

64 #'''已经创建了问题的'''

65 #for que in que_list:

66 #form = QuestionForm(instance=que)

67 #yield form

68 #return render(request,"questionedit.html",{"form":inn

你可能感兴趣的:(mysql问卷表设计)