def test_invalid(self): form_data = { 'content': '', } aboutus_form = AboutUsForm(form_data) self.assertFalse(aboutus_form.is_valid()) self.assertEqual(['This field is required.'], aboutus_form.errors['content'])
def test_invalid(self): form_data = { 'content': '', } aboutus_form = AboutUsForm(form_data) self.assertFalse(aboutus_form.is_valid()) self.assertEqual(['This field is required.'], aboutus_form .errors['content'])
def edit(request): about_us = AboutUs.objects.all()[0] about_form = AboutUsForm(instance=about_us) if request.method == "POST": about_form = AboutUsForm(instance=about_us, data=request.POST) if about_form.is_valid(): about_form.save() message = "About us content successfully updated." messages.success(request, message) return HttpResponseRedirect("/about/") return render(request, "home/edit.html", {"about_form": about_form})
def edit(request): about_us = AboutUs.objects.all()[0] about_form = AboutUsForm(instance=about_us) if request.method == 'POST': about_form = AboutUsForm(instance=about_us, data=request.POST) if about_form.is_valid(): about_form.save() message = "About us content successfully updated." messages.success(request, message) return HttpResponseRedirect(reverse('about_page')) return render(request, 'home/edit.html', {'about_form': about_form})
def edit(request): about_us = AboutUs.objects.all()[0] about_form = AboutUsForm(instance=about_us) if request.method == 'POST': about_form = AboutUsForm(instance=about_us, data=request.POST) if about_form.is_valid(): about_form.save() message = "About us content successfully updated." messages.success(request, message) return HttpResponseRedirect("/about/") return render(request, 'home/edit.html', {'about_form': about_form})
def test_valid(self): form_data = { 'content': 'description goes here', } aboutus_form = AboutUsForm(form_data) self.assertTrue(aboutus_form.is_valid())
def test_valid(self): form_data = {"content": "description goes here"} aboutus_form = AboutUsForm(form_data) self.assertTrue(aboutus_form.is_valid())
def test_invalid(self): form_data = {"content": ""} aboutus_form = AboutUsForm(form_data) self.assertFalse(aboutus_form.is_valid()) self.assertEqual(["This field is required."], aboutus_form.errors["content"])