Esempio n. 1
0
    def get(self, request):
        form = forms.PartaiForm(request.POST)
        partai = models.Partai.objects.all()

        return render(request, self.template_name, {
            'form': form,
            'partai': partai,
        })
Esempio n. 2
0
 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')
Esempio n. 3
0
    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
        })