def get(self, request): form = forms.PartaiForm(request.POST) partai = models.Partai.objects.all() return render(request, self.template_name, { 'form': form, 'partai': partai, })
def post(self, request): form = forms.PartaiForm(request.POST, request.FILES) if form.is_valid(): partai = models.Partai() partai.name = form.cleaned_data['name'] partai.no_urut = form.cleaned_data['no_urut'] partai.gambar = request.FILES['gambar'] partai.save() return redirect('/partai')
def get(self, request, id): obj = models.Partai.objects.get(id=id) data = { 'id': obj.id, 'name': obj.name, 'no_urut': obj.no_urut, 'gambar': obj.gambar } form = forms.PartaiForm(initial=data) partai = models.Partai.objects.all() return render(request, self.template_name, { 'form': form, 'partai': partai })