def edit_class(request, id=None): try: school_class = SchoolClass.objects.get(id=id) if id else None except SchoolClass.DoesNotExist: return HttpResponse(status=400) form = ClassForm(request.POST or None, instance=school_class) if form.is_valid(): school_class = form.save() if not id: request.user.LPUser.school_class.add(school_class) school_class.save() return redirect('backoffice:my_classes') return render(request, 'backoffice/edit_class.html', {'class_form': form, 'school_class': school_class})
def test_missing_school_name(self): form = ClassForm(data=self.missing_school_name) self.assertFalse(form.is_valid())
def test_valid_form(self): form = ClassForm(data=self.valid_form_data) self.assertTrue(form.is_valid())