class Staff(SoftDeletable, models.Model): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) work_email = models.EmailField() work_phone = models.CharField(max_length=100, null=True, blank=True) home_phone = models.CharField(max_length=100, null=True, blank=True) gender = models.CharField(choices=GENDER, max_length=100) residential_address = models.CharField(max_length=255, default='', blank=True) date_of_birth = models.DateField(default=timezone.now) department = models.ManyToManyField('Department', related_name='staff_department', through='Allocation') date_added = models.DateTimeField(default=timezone.now, editable=False) slug = AutoSlugField(populate_from='first_name', unique=True, default='') hardware_asset = models.ManyToManyField(Hardware, related_name='staff_hardware', through='HardwareAssign') information_asset = models.ManyToManyField(Information, related_name='staff_information', through='InformationAssign') infrastructure_asset = models.ManyToManyField(Infrastructure, related_name='staff_infrastructure', through='InfrastructureAssign') software_asset = models.ManyToManyField(Software, related_name='staff_software', through='SoftwareAssign') objects = SoftDeleteManager.from_queryset(SoftDeleteQuerySet) def __str__(self): full_name = self.first_name + ' ' + self.last_name return full_name def full_name(self): return '''{} {}'''.format(self.first_name, self.last_name) class Meta: verbose_name_plural = 'Staff' ordering = ['-date_added'] get_latest_by = ['date_added']
class DepartmentLead(SoftDeletable, models.Model): staff = models.ForeignKey(Staff, related_name='team_lead', on_delete=models.SET_NULL, null=True) lead_start_date = models.DateField(default=timezone.now, blank=True, null=True) is_lead = models.BooleanField(default=True, editable=False) added_date = models.DateTimeField(default=timezone.now, editable=False) slug = AutoSlugField(populate_from='staff', unique=True, default='') objects = SoftDeleteManager.from_queryset(SoftDeleteQuerySet) def __str__(self): return str(self.staff) class Meta: verbose_name_plural = 'Department Leads' ordering = ['added_date']
class Department(SoftDeletable, models.Model): name = models.CharField(max_length=100) description = models.TextField(default='', blank=True) team_leads = models.ForeignKey(DepartmentLead, related_name='team_lead', on_delete=models.SET_NULL, blank=True, null=True) added_date = models.DateTimeField(default=timezone.now, editable=False) slug = AutoSlugField(populate_from='name', unique=True, default='') staff = models.ManyToManyField(Staff, related_name='department_staff', through='Allocation') objects = SoftDeleteManager.from_queryset(SoftDeleteQuerySet) def __str__(self): return self.name class Meta: ordering = ['-added_date'] get_latest_by = ['added_date']
class Infrastructure(SoftDeletable, models.Model): image = models.ImageField(upload_to='infras_photo', blank=True) asset_type = models.CharField(default='Infrastructure', max_length=100) description = models.CharField(max_length=255) status = models.CharField(max_length=255, blank=True) comments = models.TextField(default='', blank=True) slug = AutoSlugField(populate_from='description', unique=True, default='') date_added = models.DateTimeField(default=timezone.now, editable=False) added_by = models.ForeignKey(User, related_name='infrastructure_admin', on_delete=models.SET_NULL, null=True) staff = models.ManyToManyField('Staff', related_name='assets_infrastructure_staff', through='InfrastructureAssign') objects = SoftDeleteManager.from_queryset(SoftDeleteQuerySet) def __str__(self): return self.description class Meta: ordering = ['-date_added'] get_latest_by = ['date_added']
class Information(SoftDeletable, models.Model): asset_type = models.CharField(default='Information', max_length=100, editable=False) added_by = models.ForeignKey(User, related_name='information_admin', on_delete=models.SET_NULL, null=True) description = models.CharField(max_length=255) status = models.CharField(max_length=255, blank=True) comments = models.TextField(default='', blank=True) # Information Fields file_type = models.CharField(choices=FILE_TYPE, max_length=255, blank=True) published_by = models.ForeignKey('Staff', related_name='publisher_staff', on_delete=models.SET_NULL, blank=True, null=True) publish_date = models.DateField(default='', blank=True) slug = AutoSlugField(populate_from='description', unique=True, default='') date_added = models.DateTimeField(default=timezone.now, editable=False) staff = models.ManyToManyField('Staff', related_name='assets_information_staff', through='InformationAssign') objects = SoftDeleteManager.from_queryset(SoftDeleteQuerySet) def __str__(self): return self.description class Meta: ordering = ['-date_added'] get_latest_by = ['date_added']