def post(self, request): form = TesOlimpiadeForm(request.POST or None, request.FILES) if form.is_valid(): tesolimpiade = TesOlimpiade() tesolimpiade.mata_pelajaran = form.cleaned_data['mata_pelajaran'] tesolimpiade.no = form.cleaned_data['no'] tesolimpiade.pertayaan = form.cleaned_data['pertayaan'] tesolimpiade.gambar = form.cleaned_data['gambar'] tesolimpiade.jawabanA = form.cleaned_data['jawabanA'] tesolimpiade.jawabanB = form.cleaned_data['jawabanB'] tesolimpiade.jawabanC = form.cleaned_data['jawabanC'] tesolimpiade.jawabanD = form.cleaned_data['jawabanD'] tesolimpiade.jawabanE = form.cleaned_data['jawabanE'] tesolimpiade.kunci = form.cleaned_data['kunci'] tesolimpiade.save() return redirect('tesolimpiade:matematika') else: return HttpResponse(form.errors)
def post(self, request, id): tesolimpiade = TesOlimpiade.objects.get(id=id) form = TesOlimpiadeForm(request.POST, request.FILES) if form.is_valid(): tesolimpiade.mata_pelajaran = form.cleaned_data['mata_pelajaran'] tesolimpiade.no = form.cleaned_data['no'] tesolimpiade.pertayaan = form.cleaned_data['pertayaan'] tesolimpiade.jawabanA = form.cleaned_data['jawabanA'] tesolimpiade.jawabanB = form.cleaned_data['jawabanB'] tesolimpiade.jawabanC = form.cleaned_data['jawabanC'] tesolimpiade.jawabanD = form.cleaned_data['jawabanD'] tesolimpiade.jawabanE = form.cleaned_data['jawabanE'] tesolimpiade.kunci = form.cleaned_data['kunci'] newpic = form.cleaned_data.get('gambar', None) if not newpic == None: tesolimpiade.gambar = newpic tesolimpiade.save(force_update=True) return redirect('tesolimpiade:matematika') else: return HttpResponse(form.errors)