from django.db import models from django.contrib.auth.models import User from django.utils.translation import gettext_lazy as _ from lib.models.base import MetaDataModel from apps.hospital.models import Hospital from apps.polyclinic.models import Polyclinic # Create your models here. class Employee(MetaDataModel): """ A model that holds the employee information that is not available in the normal user model. It has a One To One relation with the Djano User model It will inherit the attributes :attr:`~lib.models.base.MetaDataModel.created_at` and :attr:`~lib.models.base.MetaDataModel.updated_at` from the Abstract model :class:`~lib.models.base.MetaDataModel` Attributes ---------- user : User The Django user in the system where this employee data belongs to. hospital : Hospital The hospital where this employee is working. You can only choose **one** hospital per employee. polyclinic : Polyclinic The polyclinic where this employee is working within the hospital. It is possible to have / work for multiple polyclinics. phone : str Holds the direct phone number of this employee. Max length is 20 characters. """ class Meta: verbose_name = _('employee') verbose_name_plural = _('employees') user = models.OneToOneField(User, on_delete=models.CASCADE, help_text=_('Django user')) hospital = models.ForeignKey(Hospital, on_delete=models.CASCADE, help_text=_('Select the hospital for this employee')) polyclinic = models.ManyToManyField(Polyclinic, blank=True, help_text=_('Select the polyclinic(s) for this employee')) phone = models.CharField(_('Phone number'), max_length=20, blank=True, help_text=_('The direct phone number of this employee')) def __str__(self): """str: Returns a readable name for the employee. Format is [employee_full_name] ([city]).""" return '{} ({})'.format(self.user.get_full_name(), self.hospital)