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): ...@@ -51,6 +51,14 @@ class DataSource(models.Model):
category = models.CharField(max_length=32, choices=Category.choices) 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 DataSourceDetail(models.Model):
class Meta: class Meta:
......
...@@ -45,12 +45,6 @@ class DataSourceType(DjangoObjectType): ...@@ -45,12 +45,6 @@ class DataSourceType(DjangoObjectType):
'datasourceinstitusi', 'datasourcepekerja', 'datasourcewarga' 'datasourceinstitusi', 'datasourcepekerja', 'datasourcewarga'
) )
data_source_detail = graphene.Field(DataSourceDetailType) data_source_detail = graphene.Field(
DataSourceDetailType, source='get_source_detail'
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)
...@@ -2,7 +2,11 @@ import graphene ...@@ -2,7 +2,11 @@ import graphene
from graphene_django import DjangoObjectType 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 from .mustahik.query import MustahikQuery
ABOUT = ('Si Zakat merupakan sistem informasi untuk membantu masjid dalam ' 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