Fakultas Ilmu Komputer UI

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

[GREEN] implementasi model mustahik baru

parent c48bbb3c
Pipeline #51194 passed with stage
in 9 minutes and 40 seconds
......@@ -11,13 +11,8 @@ class MustahikForm(forms.ModelForm):
'no_ktp',
'phone',
'address',
'province',
'regency',
'rt',
'rw',
'birthdate',
'status',
'family_size',
'description',
'gender',
'data_source',
]
# Generated by Django 3.0.7 on 2020-07-27 04:24
# Generated by Django 3.0.7 on 2020-07-28 10:47
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
......@@ -12,6 +13,20 @@ class Migration(migrations.Migration):
]
operations = [
migrations.CreateModel(
name='DataSource',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('pic_name', models.CharField(max_length=150)),
('pic_ktp', models.CharField(max_length=32, validators=[django.core.validators.RegexValidator('^[0-9]*$', 'Numeric character only.')])),
('pic_phone', models.CharField(max_length=32, validators=[django.core.validators.RegexValidator('^[0-9]*$', 'Numeric character only.')])),
('pic_position', models.CharField(max_length=50)),
('category', models.CharField(choices=[('WARGA', 'Warga'), ('INSTITUSI', 'Institusi'), ('PEKERJA', 'Pekerja')], max_length=32)),
],
options={
'unique_together': {('pic_ktp', 'category')},
},
),
migrations.CreateModel(
name='Mustahik',
fields=[
......@@ -19,16 +34,49 @@ class Migration(migrations.Migration):
('name', models.CharField(max_length=150)),
('no_ktp', models.CharField(max_length=32, unique=True, validators=[django.core.validators.RegexValidator('^[0-9]*$', 'Numeric character only.')])),
('phone', models.CharField(blank=True, max_length=32, null=True, validators=[django.core.validators.RegexValidator('^[0-9]*$', 'Numeric character only.')])),
('address', models.TextField()),
('province', models.CharField(max_length=32)),
('regency', models.CharField(max_length=50)),
('rt', models.CharField(max_length=4, validators=[django.core.validators.RegexValidator('^[0-9]*$', 'Numeric character only.')])),
('rw', models.CharField(max_length=4, validators=[django.core.validators.RegexValidator('^[0-9]*$', 'Numeric character only.')])),
('address', models.CharField(max_length=255)),
('birthdate', models.DateField()),
('status', models.CharField(choices=[('JANDA', 'Janda'), ('MISKIN', 'Miskin'), ('YATIM', 'Yatim')], default='MISKIN', max_length=32)),
('family_size', models.PositiveSmallIntegerField()),
('description', models.TextField(blank=True, null=True)),
('status', models.CharField(choices=[('FAKIR', 'Fakir'), ('MISKIN', 'Miskin'), ('AMIL', 'Amil'), ('MUALAF', 'Mualaf'), ('GHARIM', 'Gharim'), ('FISABILILLAH', 'Fisabilillah'), ('MUSAFIR', 'Musafir')], max_length=32)),
('gender', models.CharField(choices=[('L', 'Laki-Laki'), ('P', 'Perempuan')], max_length=1)),
('photo', models.FileField(default='images/default_photo.jpg', upload_to='images/mustahik')),
('data_source', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mustahik.DataSource')),
],
),
migrations.CreateModel(
name='DataSourceWarga',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('province', models.CharField(max_length=50)),
('regency', models.CharField(max_length=50)),
('sub_district', models.CharField(max_length=50)),
('village', models.CharField(max_length=50)),
('rt', models.CharField(max_length=3, validators=[django.core.validators.RegexValidator('^[0-9]*$', 'Numeric character only.')])),
('rw', models.CharField(max_length=3, validators=[django.core.validators.RegexValidator('^[0-9]*$', 'Numeric character only.')])),
('data_source', models.OneToOneField(limit_choices_to={'category': 'WARGA'}, on_delete=django.db.models.deletion.CASCADE, to='mustahik.DataSource')),
],
),
migrations.CreateModel(
name='DataSourcePekerja',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('profession', models.CharField(max_length=50)),
('location', models.CharField(max_length=50)),
('data_source', models.OneToOneField(limit_choices_to={'category': 'PEKERJA'}, on_delete=django.db.models.deletion.CASCADE, to='mustahik.DataSource')),
],
),
migrations.CreateModel(
name='DataSourceInstitusi',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=150)),
('province', models.CharField(max_length=50)),
('regency', models.CharField(max_length=50)),
('sub_district', models.CharField(max_length=50)),
('village', models.CharField(max_length=50)),
('rt', models.CharField(max_length=3, validators=[django.core.validators.RegexValidator('^[0-9]*$', 'Numeric character only.')])),
('rw', models.CharField(max_length=3, validators=[django.core.validators.RegexValidator('^[0-9]*$', 'Numeric character only.')])),
('address', models.CharField(max_length=255)),
('data_source', models.OneToOneField(limit_choices_to={'category': 'INSTITUSI'}, on_delete=django.db.models.deletion.CASCADE, to='mustahik.DataSource')),
],
),
]
import os
from django.db import models
from django.utils import timezone
......@@ -6,9 +8,13 @@ from sizakat.validators import validate_numeric_character
class Mustahik(models.Model):
class Status(models.TextChoices):
JANDA = ('JANDA', 'Janda')
FAKIR = ('FAKIR', 'Fakir')
MISKIN = ('MISKIN', 'Miskin')
YATIM = ('YATIM', 'Yatim')
AMIL = ('AMIL', 'Amil')
MUALAF = ('MUALAF', 'Mualaf')
GHARIM = ('GHARIM', 'Gharim')
FISABILILLAH = ('FISABILILLAH', 'Fisabilillah')
MUSAFIR = ('MUSAFIR', 'Musafir')
class Gender(models.TextChoices):
LAKILAKI = ('L', 'Laki-Laki')
......@@ -23,24 +29,82 @@ class Mustahik(models.Model):
max_length=32, blank=True, null=True,
validators=[validate_numeric_character]
)
address = models.TextField()
province = models.CharField(max_length=32)
address = models.CharField(max_length=255)
birthdate = models.DateField()
status = models.CharField(max_length=32, choices=Status.choices)
gender = models.CharField(max_length=1, choices=Gender.choices)
photo = models.FileField(
upload_to=os.path.join('images', 'mustahik'),
default=os.path.join('images', 'default_photo.jpg')
)
data_source = models.ForeignKey('DataSource', on_delete=models.CASCADE)
def calculate_age(self):
return timezone.now().year - self.birthdate.year
class DataSource(models.Model):
class Category(models.TextChoices):
WARGA = ('WARGA', 'Warga')
INSTITUSI = ('INSTITUSI', 'Institusi')
PEKERJA = ('PEKERJA', 'Pekerja')
pic_name = models.CharField(max_length=150)
pic_ktp = models.CharField(
max_length=32,
validators=[validate_numeric_character]
)
pic_phone = models.CharField(
max_length=32,
validators=[validate_numeric_character]
)
pic_position = models.CharField(max_length=50)
category = models.CharField(max_length=32, choices=Category.choices)
class Meta:
unique_together = ('pic_ktp', 'category',)
class DataSourceWarga(models.Model):
province = models.CharField(max_length=50)
regency = models.CharField(max_length=50)
sub_district = models.CharField(max_length=50)
village = models.CharField(max_length=50)
rt = models.CharField(
max_length=4, validators=[validate_numeric_character]
max_length=3, validators=[validate_numeric_character]
)
rw = models.CharField(
max_length=4, validators=[validate_numeric_character]
max_length=3, validators=[validate_numeric_character]
)
birthdate = models.DateField()
status = models.CharField(
max_length=32,
choices=Status.choices,
default=Status.MISKIN,
data_source = models.OneToOneField(
'DataSource', on_delete=models.CASCADE,
limit_choices_to={'category': DataSource.Category.WARGA}
)
family_size = models.PositiveSmallIntegerField()
description = models.TextField(blank=True, null=True)
gender = models.CharField(max_length=1, choices=Gender.choices)
def calculate_age(self):
return timezone.now().year - self.birthdate.year
class DataSourceInstitusi(models.Model):
name = models.CharField(max_length=150)
province = models.CharField(max_length=50)
regency = models.CharField(max_length=50)
sub_district = models.CharField(max_length=50)
village = models.CharField(max_length=50)
rt = models.CharField(
max_length=3, validators=[validate_numeric_character]
)
rw = models.CharField(
max_length=3, validators=[validate_numeric_character]
)
address = models.CharField(max_length=255)
data_source = models.OneToOneField(
'DataSource', on_delete=models.CASCADE,
limit_choices_to={'category': DataSource.Category.INSTITUSI}
)
class DataSourcePekerja(models.Model):
profession = models.CharField(max_length=50)
location = models.CharField(max_length=50)
data_source = models.OneToOneField(
'DataSource', on_delete=models.CASCADE,
limit_choices_to={'category': DataSource.Category.PEKERJA}
)
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