aboutsummaryrefslogblamecommitdiffstats
path: root/ctrack/users/models.py
blob: 93c086a42b2797a30629b312c00c1c086000938b (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                   
                            


                                                       
                                                                          
 

                         



                                                                          


                                                                          
 
             






                                        
                               
                                                            





                                                                      
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _

from ctrack.organisations.models import Stakeholder, Submode, Organisation


class User(AbstractUser):
    name = models.CharField(_("Name of User"), blank=True, max_length=255)
    stakeholder = models.OneToOneField(
        Stakeholder, on_delete=models.CASCADE, null=True, blank=True
    )

    def get_absolute_url(self):
        return reverse("users:detail", kwargs={"username": self.username})

    @property
    def is_stakeholder(self):
        if self.stakeholder is not None:
            return True
        else:
            return False

    def get_organisation_name(self):
        if self.is_stakeholder:
            return self.stakeholder.person.organisation.name

    def get_lead_inspector_organisations(self):
        return Organisation.objects.filter(lead_inspector=self)

    def get_deputy_lead_inspector_organisations(self):
        return Organisation.objects.filter(deputy_lead_inspector=self)