Fakultas Ilmu Komputer UI

mutations.py 1.25 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import graphene

from django import forms
from graphene_django.forms.mutation import DjangoModelFormMutation

from .models import Mustahik
from .types import MustahikType


class MustahikForm(forms.ModelForm):

    class Meta:
        model = Mustahik
        fields = [
            'name',
            'no_ktp',
            'phone',
            'address',
            'province',
            'regency',
            'rt',
            'rw',
            'birthdate',
            'status',
            'family_size',
            'description',
        ]


class MustahikMutation(DjangoModelFormMutation):

    mustahik = graphene.Field(MustahikType)

    class Meta:
35
36
37
38
39
40
        form_class = MustahikForm

class DeleteMustahik(graphene.Mutation): 
    class Arguments:
        id = graphene.ID()
    
41
42
43
44
    message = graphene.String()
    idMustahik = graphene.ID()
    nama = graphene.String()
    noKtp = graphene.String()
45
46
47
48
    mustahik = graphene.Field(MustahikType)

    def mutate(self, info, id):
        mustahik = Mustahik.objects.get(pk=id)
49
50
51
52
53
        _nama = mustahik.name
        _no_ktp = mustahik.no_ktp
        mustahik.delete()
        return DeleteMustahik(message = "Success", idMustahik=id, nama=_nama, noKtp=_no_ktp)

54