Skip to content

Instantly share code, notes, and snippets.

@solanoize
Created July 20, 2016 14:39
Show Gist options
  • Select an option

  • Save solanoize/e72e0a013b36142cdc89765cdd011de6 to your computer and use it in GitHub Desktop.

Select an option

Save solanoize/e72e0a013b36142cdc89765cdd011de6 to your computer and use it in GitHub Desktop.
Base Model Sistem Absensi Siswa
from django.db import models
from django.utils import timezone
class Kelas(models.Model):
kelas = models.CharField(max_length=32, unique=True)
def __str__(self):
return self.kelas
class Meta:
db_table = 'kelas'
class Siswa(models.Model):
nis = models.CharField(max_length=4, unique=True)
nama = models.CharField(max_length=50)
kelas = models.ForeignKey(Kelas, related_name="kelas_siswa")
def __str__(self):
return self.nis
class Meta:
db_table = 'siswa'
class Semester(models.Model):
PILIHAN_STATUS = (
('Y', 'Ganjil'),
('N', 'Genap'),
)
status = models.CharField(max_length=1, choices=PILIHAN_STATUS, default='Y')
def __str__(self):
return self.status
class Meta:
db_table = 'semester'
class Absens(models.Model):
STATUS_ABSENSI = (
('S', 'Sakit'),
('I', 'Izin'),
('A', 'Alpa'),
('M', 'Masuk'),
)
nis = models.ForeignKey(Siswa)
semester = models.ForeignKey(Semester)
tanggal = models.DateField(default=timezone.now)
absen = models.CharField(max_length=1, choices=STATUS_ABSENSI, default='M')
def __str__(self):
return self.nis.nama
class Meta:
db_table = 'absen'
unique_together = ('nis', 'tanggal')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment