1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
from django.db import models
from django.contrib.auth import get_user_model
from django.urls import reverse
from django.conf import settings
from django_extensions.db.fields import AutoSlugField
from slugify import slugify
class AddressType(models.Model):
descriptor = models.CharField(max_length=50)
def __str__(self):
return self.descriptor
class Role(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class Person(models.Model):
TITLES = [
(1, "Mr"),
(2, "Mrs"),
(3, "Miss"),
(4, "Ms"),
(5, "Dr."),
(6, "Professor"),
(7, "The Rt Hon."),
(8, "Lord"),
(9, "Lady"),
]
CLEARANCE_LEVEL = [
(1, "NA"),
(2, "BPSS"),
(3, "CTC"),
(4, "SC"),
(5, "DV"),
(6, "Other"),
]
primary_nis_contact = models.BooleanField(default=False, verbose_name="Primary NIS contact")
voluntary_point_of_contact = models.BooleanField(default=False)
has_egress = models.BooleanField(default=False, verbose_name="Has Egress")
title = models.IntegerField(choices=TITLES, default=1)
job_title = models.CharField(max_length=100)
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
organisation = models.ForeignKey("Organisation", on_delete=models.CASCADE)
role = models.ManyToManyField(Role)
email = models.EmailField()
secondary_email = models.EmailField(blank=True)
mobile = models.CharField(max_length=20, blank=True)
landline = models.CharField(max_length=20, blank=True)
date_updated = models.DateField(auto_now=True)
updated_by = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
clearance = models.IntegerField(choices=CLEARANCE_LEVEL, default=1)
clearance_sponsor = models.CharField(max_length=100, blank=True)
clearance_start_date = models.DateField(blank=True)
clearance_last_checked = models.DateField(blank=True)
clearance_expiry = models.DateField(blank=True)
active = models.BooleanField(default=True)
date_ended = models.DateField(blank=True)
predecessor = models.ForeignKey('self', blank=True, on_delete=models.CASCADE, related_name="previous_person")
comments = models.TextField(max_length=1000)
def __str__(self):
return self.name
def get_organisation_name(self):
return self.organisation.name
class Meta:
verbose_name_plural = "People"
class Mode(models.Model):
descriptor = models.CharField(max_length=100)
def __str__(self):
return self.descriptor
class Submode(models.Model):
descriptor = models.CharField(max_length=100)
mode = models.ForeignKey(Mode, on_delete=models.CASCADE)
def __str__(self):
return self.descriptor
class Organisation(models.Model):
DESIGNATION_TYPE = [
(1, "Automatic"),
(2, "Reserve Power"),
]
name = models.CharField(max_length=255)
slug = AutoSlugField(populate_from=["name"])
submode = models.ForeignKey(
Submode, on_delete=models.CASCADE, blank=True, null=True
)
designation_type = models.IntegerField(choices=DESIGNATION_TYPE, default=1)
registered_company_name = models.CharField(max_length=255, blank=True)
registered_company_number = models.CharField(max_length=100, blank=True)
date_updated = models.DateField(auto_now=True)
updated_by = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
comments = models.TextField(max_length=500)
active = models.BooleanField(default=True)
def get_absolute_url(self):
return reverse("organisations:detail", kwargs={"slug": self.slug})
def slugify_name(self):
return slugify(self.name)
def __str__(self):
return self.name
class Address(models.Model):
organisation = models.ForeignKey(
Organisation, related_name="addresses", on_delete=models.CASCADE, blank=False
)
type = models.ForeignKey(
AddressType, verbose_name="Address Type", on_delete=models.CASCADE, blank=False
)
line1 = models.CharField(max_length=255)
line2 = models.CharField(max_length=255, blank=True)
line3 = models.CharField(max_length=255, blank=True)
city = models.CharField(max_length=100)
county = models.CharField(max_length=100, blank=True)
postcode = models.CharField(max_length=10)
country = models.CharField(max_length=100)
other_details = models.CharField(max_length=255, blank=True)
def __str__(self):
return " ".join([self.organisation.name, self.line1])
class Meta:
verbose_name_plural = "Addresses"
|