Fakultas Ilmu Komputer UI

Commit 6f594867 authored by addffa's avatar addffa
Browse files

[REFACTOR] memindahkan fungsi get detil ke model

parent b752cb6c
......@@ -51,6 +51,14 @@ class DataSource(models.Model):
category = models.CharField(max_length=32, choices=Category.choices)
def get_source_detail(self):
if self.category == DataSource.Category.INSTITUSI:
return DataSourceInstitusi.objects.get(data_source=self)
if self.category == DataSource.Category.PEKERJA:
return DataSourcePekerja.objects.get(data_source=self)
if self.category == DataSource.Category.WARGA:
return DataSourceWarga.objects.get(data_source=self)
class DataSourceDetail(models.Model):
class Meta:
......
......@@ -45,12 +45,6 @@ class DataSourceType(DjangoObjectType):
'datasourceinstitusi', 'datasourcepekerja', 'datasourcewarga'
)
data_source_detail = graphene.Field(DataSourceDetailType)
def resolve_data_source_detail(self, info):
if self.category == DataSource.Category.INSTITUSI:
return DataSourceInstitusi.objects.get(data_source__pk=self.pk)
if self.category == DataSource.Category.PEKERJA:
return DataSourcePekerja.objects.get(data_source__pk=self.pk)
if self.category == DataSource.Category.WARGA:
return DataSourceWarga.objects.get(data_source__pk=self.pk)
data_source_detail = graphene.Field(
DataSourceDetailType, source='get_source_detail'
)
......@@ -2,7 +2,11 @@ import graphene
from graphene_django import DjangoObjectType
from .mustahik.mutations import MustahikMutation, DeleteMustahik, DataSourceMutation, DataSourceWargaMutation, DataSourceInstitusiMutation, DataSourcePekerjaMutation
from .mustahik.mutations import (
MustahikMutation, DeleteMustahik, DataSourceMutation,
DataSourceWargaMutation, DataSourceInstitusiMutation,
DataSourcePekerjaMutation
)
from .mustahik.query import MustahikQuery
ABOUT = ('Si Zakat merupakan sistem informasi untuk membantu masjid dalam '
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment