Created
December 28, 2012 03:28
-
-
Save widoyo/4394221 to your computer and use it in GitHub Desktop.
Model Ideal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.contrib.auth.models import User | |
from django.contrib.contenttypes.models import ContentType | |
from django.contrib.contenttypes import generic | |
from django.db.models import signals | |
class ModuleRef(models.Model): | |
""" | |
Referensi Module, Part Number | |
""" | |
partnum = models.CharField(max_length=50, unique=True) | |
desc = models.CharField(max_length=255, null=True, blank=True) | |
cdate = models.DateTimeField(auto_now_add=True) | |
mdate = models.DateTimeField(auto_now=True) | |
def __unicode__(self): | |
return self.partnum | |
class Meta: | |
db_table = 'moduleref' | |
class Pool(models.Model): | |
""" | |
Pool Sparepart atau Satellite Warehoue (SWH) | |
""" | |
name = models.CharField(max_length=50, unique=True) | |
address = models.CharField(max_length=255, null=True, blank=True) | |
phone = models.CharField(max_length=35, null=True, blank=True) | |
fax = models.CharField(max_length=35, null=True, blank=True) | |
hp = models.CharField(max_length=35, null=True, blank=True) | |
supervisor = models.CharField(max_length=35, null=True, blank=True) | |
parent = models.ForeignKey('self', null=True, blank=True) | |
region = models.IntegerField(null=True, blank=True) | |
wbs = models.CharField(max_length=20, null=True, blank=True) | |
ll = models.CharField(max_length=100, null=True, blank=True) | |
def __unicode__(self): | |
return self.name | |
def get_absolute_url(self): | |
return '/pool/%s/' % (self.id) | |
class Meta: | |
db_table = 'pool' | |
class Customer(models.Model): | |
name = models.CharField(max_length=35, unique=True) | |
initial = models.CharField(max_length=1, unique=True) | |
def __unicode__(self): | |
return self.name | |
class Meta: | |
db_table = 'customer' | |
class Engineer(models.Model): | |
name = models.CharField(max_length=50) | |
hp1 = models.CharField(max_length=30, null=True, blank=True) | |
email = models.CharField(max_length=30, null=True, blank=True) | |
customer = models.ForeignKey(Customer) | |
def __unicode__(self): | |
return self.name | |
class Meta: | |
db_table = 'engineer' | |
class TSite(models.Model): | |
""" | |
Telecom Site | |
""" | |
number = models.CharField(max_length=50, unique=True) | |
name = models.CharField(max_length=100) | |
address = models.CharField(max_length=200, null=True, blank=True) | |
phone = models.CharField(max_length=35, null=True, blank=True) | |
fax = models.CharField(max_length=35, null=True, blank=True) | |
customer = models.ForeignKey(Customer) | |
cdate = models.DateTimeField(auto_now_add=True) | |
mdate = models.DateTimeField(auto_now=True) | |
cu = models.ForeignKey(User, related_name="ts_cu", null=True, blank=True, editable=False) | |
mu = models.ForeignKey(User, related_name="ts_mu", null=True, blank=True, editable=False) | |
def __unicode__(self): | |
return self.name | |
class Meta: | |
db_table = 'site' | |
verbose_name = "Telecom Site" | |
verbose_name_plural = verbose_name | |
class BOQ(models.Model): | |
""" | |
BillOfQuantity, batas minimal tersedianya tiap partnum | |
""" | |
pool = models.ForeignKey(Pool) | |
partnum = models.ForeignKey(ModuleRef) | |
batas = models.IntegerField() # batas minimal tersedia | |
qty = models.IntegerField() # current qty | |
def __unicode__(self): | |
return self.partnum | |
class Meta: | |
db_table = 'boq' | |
VENDOR_CHOICES = ( | |
(1, 'NSN'), | |
(2, 'HCPT'), | |
(3, 'HP'), | |
(4, 'Fujitsu') | |
) | |
class Sparepart(models.Model): | |
""" | |
Telecom Sparepart, the real sparepart, 1 record per serial num | |
""" | |
partnum = models.ForeignKey(ModuleRef) | |
sn = models.CharField(max_length=50, unique=True) | |
faulty = models.BooleanField(default=False) # faulty status | |
pool = models.ForeignKey(Pool) # latest pool location, updated on MDD, FPR | |
owner = models.IntegerField(choices=VENDOR_CHOICES, default=1) # pemilik module | |
cdate = models.DateTimeField(auto_now_add=True) # created at | |
mdate = models.DateTimeField(auto_now=True) # modified at | |
cu = models.ForeignKey(User, related_name="sp_cu", null=True, blank=True, editable=False) # user creator this record | |
mu = models.ForeignKey(User, related_name="sp_mu", null=True, blank=True, editable=False) # user modifier this record | |
def __unicode__(self): | |
return self.sn | |
class Meta: | |
db_table = 'sparepart' | |
REQUEST_BY_CHOICES = ( | |
('1', 'Phone'), | |
('2', 'Fax'), | |
('3', 'Email'), | |
('4', 'Direct') | |
) | |
class RMR(models.Model): | |
""" | |
Replacement Module Request | |
""" | |
seq = models.IntegerField() # awal tahun kembali ke 1 | |
requested = models.DateTimeField() # tanggal request | |
site = models.ForeignKey(TSite) # delivered to this site | |
by = models.CharField(max_length=1, choices=REQUEST_BY_CHOICES) | |
personel = models.CharField(max_length="50", null=True, blank=True) # Who is request | |
cdate = models.DateTimeField(auto_now_add=True) # created at | |
mdate = models.DateTimeField(auto_now=True) # modified at | |
cu = models.ForeignKey(User, related_name="rmr_cu", null=True, blank=True, editable=False) # user creator this record | |
mu = models.ForeignKey(User, related_name="rmr_mu", null=True, blank=True, editable=False) # user modifier this record | |
def __unicode__(self): | |
return "%s-%s" % (self.requested.strftime('%y%m%d'), self.seq) | |
class Meta: | |
db_table = 'rmr' | |
verbose_name = 'RMR' | |
verbose_name_plural = verbose_name | |
class RMRItem(models.Model): | |
rmr = models.ForeignKey(RMR) | |
utype = models.CharField(max_length=35, null=True, blank=True) # usage type: BSS | |
partnum = models.ForeignKey(ModuleRef) | |
qty = models.IntegerField(default=1) | |
class Meta: | |
db_table = 'rmr_item' | |
class MDD(models.Model): | |
""" | |
Module Delivery Document | |
""" | |
seq = models.IntegerField() | |
rmr = models.ForeignKey(RMR) | |
supposed_delivered = models.DateTimeField() # diharapkan datang | |
mttr = models.IntegerField() # in menit MTTR | |
delivered = models.DateTimeField(null=True, blank=True) # datetime delivered | |
rmc = models.CharField(max_length=50, null=True, blank=True) # received by | |
inti = models.CharField(max_length=50, null=True, blank=True) # delivered by | |
cdate = models.DateTimeField(auto_now_add=True) # created at | |
mdate = models.DateTimeField(auto_now=True) # modified at | |
cu = models.ForeignKey(User, related_name="mdd_cu", null=True, blank=True, editable=False) # user creator this record | |
mu = models.ForeignKey(User, related_name="mdd_mu", null=True, blank=True, editable=False) # user modifier this record | |
def __unicode__(self): | |
return "%s" % self.seq | |
class Meta: | |
db_table = 'mdd' | |
class MDDItem(models.Model): | |
""" | |
Sparepart Item to delivered, base on RMR Item | |
""" | |
mdd = models.ForeignKey(MDD) | |
rmritem = models.ForeignKey(RMRItem) | |
sparepart = models.ForeignKey(Sparepart) | |
class Meta: | |
db_table = 'mdd_item' | |
class FPR(models.Model): | |
""" | |
Faulty Part Returns | |
""" | |
seq = models.IntegerField() # sequence, return 1 on new year | |
received = models.DateTimeField() # received at | |
by = models.CharField(max_length=50, null=True, blank=True) # sparelog representative | |
cdate = models.DateTimeField(auto_now_add=True) # created at | |
mdate = models.DateTimeField(auto_now=True) # modified at | |
cu = models.ForeignKey(User, related_name="fpr_cu", null=True, blank=True, editable=False) # user creator this record | |
mu = models.ForeignKey(User, related_name="fpr_mu", null=True, blank=True, editable=False) # user modifier this record | |
class Meta: | |
db_table = 'fpr' | |
class FPRItem(models.Model): | |
fpr = models.ForeignKey(FPR) | |
rmr = models.ForeignKey(RMR) | |
sparepart = models.ForeignKey(Sparepart) | |
remark = models.CharField(max_length=255, null=True, blank=True) | |
class Meta: | |
db_table = 'fpr_item' | |
class Berkas(models.Model): | |
""" | |
Uploaded documents | |
""" | |
name = models.ImageField(upload_to='berkas') | |
content_type = models.ForeignKey(ContentType) | |
object_id = models.PositiveIntegerField() | |
content_object = generic.GenericForeignKey('content_type', 'object_id') | |
cdate = models.DateTimeField(auto_now_add=True) # created at | |
mdate = models.DateTimeField(auto_now=True) # modified at | |
cu = models.ForeignKey(User, related_name="doc_cu", null=True, blank=True, editable=False) # user creator this record | |
mu = models.ForeignKey(User, related_name="doc_mu", null=True, blank=True, editable=False) # user modifier this record | |
class Meta: | |
db_table = 'berkas' | |
class UserProfile(models.Model): | |
user = models.ForeignKey(User, unique=True) | |
pool = models.ForeignKey(Pool, null=True) | |
def __unicode__(self): | |
return self.user.username | |
class Meta: | |
db_table = u'userprofile' | |
def create_user_profile(instance, created, **kwargs): | |
try: | |
up = UserProfile(user=instance) | |
up.save() | |
except: | |
pass | |
signals.post_save.connect(create_user_profile, sender=User) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment