如何在django中验证表单集

bgibtngc  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(278)

我正在使用formset将数据输入数据库,但由于某些原因,每当我在终端中进行测试并调用.is_valid()时,它都不会验证。无论我做什么尝试,它都会返回false。下面是my views.py和forms.py中的代码。任何帮助都将不胜感激!


# Advanced Subjects (Advanced Biology)

def form_5_entry_biology_view(self, request):
    current_teacher = User.objects.get(email=request.user.email)
    logged_school = current_teacher.school_number
    students_involved = User.objects.get(school_number=logged_school).teacher.all()
    data = {'student_name': students_involved}
    formset_data = AdvancedStudents.objects.filter(class_studying='Form V', combination='PCB')
    student_formset = formset_factory(AdvancedBiologyForm, extra=0)
    initial = []
    for element in formset_data:
        initial.append({'student_name': element})
    formset = student_formset(request.POST or None, initial=initial)
    print(formset.is_valid())
    context = {'students': students_involved,
               'formset': formset,
               'class_of_students': 'Form V',
               'subject_name': 'Advanced Biology'}
    return render(request, 'analyzer/marks_entry/marks_entry_page.html', context)

这是我的表格

class AdvancedBiologyForm(forms.ModelForm):
    student_name = forms.CharField()

    class Meta:
        model = ResultsALevel
        fields = ('student_name', 'advanced_biology_1', 'advanced_biology_2', 
                   'advanced_biology_3',)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题