2020-05-13 15:54:40 +02:00
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 ) :
2020-05-18 14:22:52 +02:00
"""
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 .
"""
2020-05-15 10:31:22 +02:00
class Meta :
2020-05-15 12:54:16 +02:00
verbose_name = _ ( ' employee ' )
verbose_name_plural = _ ( ' employees ' )
2020-05-15 10:31:22 +02:00
2020-05-13 15:54:40 +02:00
user = models . OneToOneField ( User , on_delete = models . CASCADE , help_text = _ ( ' Django user ' ) )
2020-05-19 16:13:34 +02:00
hospital = models . ForeignKey ( Hospital , verbose_name = Hospital . _meta . verbose_name , on_delete = models . CASCADE , help_text = _ ( ' Select the hospital for this employee ' ) )
2020-05-13 15:54:40 +02:00
2020-05-19 16:13:34 +02:00
polyclinic = models . ManyToManyField ( Polyclinic , verbose_name = Polyclinic . _meta . verbose_name , blank = True , help_text = _ ( ' Select the polyclinic(s) for this employee ' ) )
2020-05-18 14:22:52 +02:00
phone = models . CharField ( _ ( ' Phone number ' ) , max_length = 20 , blank = True , help_text = _ ( ' The direct phone number of this employee ' ) )
2020-05-13 15:54:40 +02:00
def __str__ ( self ) :
2020-05-18 14:22:52 +02:00
""" str: Returns a readable name for the employee. Format is [employee_full_name] ([city]). """
2020-05-13 15:54:40 +02:00
return ' {} ( {} ) ' . format ( self . user . get_full_name ( ) , self . hospital )