More models
This commit is contained in:
parent
e533710345
commit
8771e425ed
9 changed files with 339 additions and 15 deletions
|
@ -0,0 +1,108 @@
|
|||
# Generated by Django 4.1 on 2022-08-09 06:34
|
||||
|
||||
import datastore.helpers.uploads
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('datastore', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Address',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('address', models.TextField()),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Airport',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('city_code', models.CharField(blank=True, max_length=256, null=True)),
|
||||
('code', models.CharField(blank=True, max_length=256, null=True, unique=True)),
|
||||
('country_name', models.CharField(blank=True, max_length=256, null=True)),
|
||||
('name', models.CharField(blank=True, max_length=256, null=True)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='APIUser',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('username', models.CharField(max_length=256)),
|
||||
('password', models.CharField(max_length=256)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Country',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('code', models.CharField(max_length=16)),
|
||||
('text', models.CharField(max_length=128)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Nationality',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('country', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='datastore.country')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='PhoneCode',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('code', models.CharField(max_length=16)),
|
||||
('flag', models.ImageField(null=True, upload_to=datastore.helpers.uploads.get_upload_path)),
|
||||
('text', models.CharField(max_length=128)),
|
||||
],
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='date_joined',
|
||||
field=models.DateTimeField(auto_now_add=True),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ZipPlaces',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('postcode', models.CharField(max_length=64)),
|
||||
('postplace', models.CharField(max_length=256)),
|
||||
('country', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='datastore.nationality')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='CrewMember',
|
||||
fields=[
|
||||
('pin', models.IntegerField(primary_key=True, serialize=False)),
|
||||
('first_name', models.CharField(max_length=128)),
|
||||
('middle_name', models.CharField(blank=True, max_length=128, null=True)),
|
||||
('last_name', models.CharField(max_length=128)),
|
||||
('calling_name', models.CharField(max_length=128)),
|
||||
('place_of_birth', models.CharField(max_length=128)),
|
||||
('first_address', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='crew_first', to='datastore.address')),
|
||||
('nationality', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='datastore.nationality')),
|
||||
('second_address', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='crew_second', to='datastore.address')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='APIToken',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('value', models.UUIDField(default=uuid.uuid4)),
|
||||
('expiry', models.DateTimeField()),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='datastore.apiuser')),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='address',
|
||||
name='zipplace',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='datastore.zipplaces'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,39 @@
|
|||
# Generated by Django 4.1 on 2022-08-09 06:42
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('datastore', '0002_address_airport_apiuser_country_nationality_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Competence',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=256)),
|
||||
('shortname', models.CharField(max_length=64)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Role',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=128)),
|
||||
('competences', models.ManyToManyField(null=True, to='datastore.competence')),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='crewmember',
|
||||
name='competences',
|
||||
field=models.ManyToManyField(null=True, to='datastore.competence'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='crewmember',
|
||||
name='roles',
|
||||
field=models.ManyToManyField(null=True, to='datastore.role'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,46 @@
|
|||
# Generated by Django 4.1 on 2022-08-09 07:11
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('datastore', '0003_competence_role_crewmember_competences_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='crewmember',
|
||||
name='closest_airport',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, related_name='crew_first', to='datastore.airport'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='crewmember',
|
||||
name='country_of_birth',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, to='datastore.country'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='crewmember',
|
||||
name='second_airport',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='crew_second', to='datastore.airport'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='crewmember',
|
||||
name='suffix_name',
|
||||
field=models.CharField(blank=True, max_length=128, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='crewmember',
|
||||
name='title',
|
||||
field=models.CharField(blank=True, max_length=128, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='crewmember',
|
||||
name='calling_name',
|
||||
field=models.CharField(blank=True, max_length=128, null=True),
|
||||
),
|
||||
]
|
40
datastore/migrations/0005_crewmember_initials_phone_email.py
Normal file
40
datastore/migrations/0005_crewmember_initials_phone_email.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
# Generated by Django 4.1 on 2022-08-09 07:17
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('datastore', '0004_crewmember_closest_airport_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='crewmember',
|
||||
name='initials',
|
||||
field=models.CharField(blank=True, max_length=16, null=True),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Phone',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('number', models.CharField(max_length=128)),
|
||||
('confirmed', models.BooleanField(default=True)),
|
||||
('priority', models.IntegerField(default=0)),
|
||||
('crew', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='datastore.crewmember')),
|
||||
('idc', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='datastore.phonecode')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Email',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('email', models.EmailField(max_length=254)),
|
||||
('confirmed', models.BooleanField(default=True)),
|
||||
('priority', models.IntegerField(default=0)),
|
||||
('crew', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='datastore.crewmember')),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -0,0 +1,38 @@
|
|||
# Generated by Django 4.1 on 2022-08-09 07:32
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('datastore', '0005_crewmember_initials_phone_email'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='competence',
|
||||
name='shortname',
|
||||
field=models.CharField(max_length=64, unique=True),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Certificate',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_by', models.CharField(blank=True, max_length=128, null=True)),
|
||||
('create_time', models.DateTimeField(blank=True, null=True)),
|
||||
('changed_by', models.CharField(blank=True, max_length=128, null=True)),
|
||||
('date_from', models.DateField(blank=True, null=True)),
|
||||
('date_to', models.DateField(blank=True, null=True)),
|
||||
('issued_by', models.CharField(blank=True, max_length=128, null=True)),
|
||||
('issued_place', models.CharField(blank=True, max_length=128, null=True)),
|
||||
('certificate_number', models.CharField(blank=True, max_length=128, null=True)),
|
||||
('expiry_date', models.DateField(blank=True, null=True)),
|
||||
('comments', models.TextField(blank=True, null=True)),
|
||||
('planned', models.BooleanField(default=False)),
|
||||
('competence', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='datastore.competence')),
|
||||
('crew', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='datastore.crewmember')),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -1 +1,4 @@
|
|||
from .auth import User
|
||||
from .crew import CrewMember
|
||||
from .places import Airport, Country, Nationality, PhoneCode, ZipPlaces
|
||||
from .competences import Competence, Role, Certificate
|
|
@ -0,0 +1,25 @@
|
|||
from django.db import models
|
||||
|
||||
|
||||
class Competence(models.Model):
|
||||
name = models.CharField(max_length=256)
|
||||
shortname = models.CharField(max_length=64, unique=True)
|
||||
|
||||
class Role(models.Model):
|
||||
name = models.CharField(max_length=128)
|
||||
competences = models.ManyToManyField(Competence, null=True)
|
||||
|
||||
class Certificate(models.Model):
|
||||
crew = models.ForeignKey("crewmember", models.CASCADE)
|
||||
competence = models.ForeignKey(Competence, models.CASCADE)
|
||||
created_by = models.CharField(max_length=128, null=True, blank=True)
|
||||
create_time = models.DateTimeField(null=True, blank=True)
|
||||
changed_by = models.CharField(max_length=128, null=True, blank=True)
|
||||
date_from = models.DateField(null=True, blank=True)
|
||||
date_to = models.DateField(null=True, blank=True)
|
||||
issued_by = models.CharField(max_length=128, null=True, blank=True)
|
||||
issued_place = models.CharField(max_length=128, null=True, blank=True)
|
||||
certificate_number = models.CharField(max_length=128, null=True, blank=True)
|
||||
expiry_date = models.DateField(null=True, blank=True)
|
||||
comments = models.TextField(null=True, blank=True)
|
||||
planned = models.BooleanField(default=False)
|
|
@ -1,7 +1,11 @@
|
|||
from django.db import models
|
||||
|
||||
from .places import Nationality, ZipPlaces
|
||||
from .places import Nationality, ZipPlaces, Country, Airport, PhoneCode
|
||||
from .competences import Competence, Role
|
||||
|
||||
class Address(models.Model):
|
||||
address = models.TextField()
|
||||
zipplace = models.ForeignKey(ZipPlaces, models.PROTECT)
|
||||
|
||||
class CrewMember(models.Model):
|
||||
pin = models.IntegerField(primary_key=True)
|
||||
|
@ -9,14 +13,35 @@ class CrewMember(models.Model):
|
|||
first_name = models.CharField(max_length=128)
|
||||
middle_name = models.CharField(max_length=128, null=True, blank=True)
|
||||
last_name = models.CharField(max_length=128)
|
||||
calling_name = models.CharField(max_length=128)
|
||||
calling_name = models.CharField(max_length=128, null=True, blank=True)
|
||||
suffix_name = models.CharField(max_length=128, null=True, blank=True)
|
||||
title = models.CharField(max_length=128, null=True, blank=True)
|
||||
initials = models.CharField(max_length=16, null=True, blank=True)
|
||||
|
||||
nationality = models.ForeignKey(Nationality, models.PROTECT)
|
||||
place_of_birth = models.CharField(max_length=128)
|
||||
first_address = models.ForeignKey(Address, models.PROTECT)
|
||||
second_address = models.ForeignKey(Address, models.PROTECT, null=True)
|
||||
country_of_birth = models.ForeignKey(Country, models.PROTECT)
|
||||
first_address = models.ForeignKey(Address, models.PROTECT, related_name="crew_first")
|
||||
second_address = models.ForeignKey(Address, models.PROTECT, null=True, related_name="crew_second")
|
||||
closest_airport = models.ForeignKey(Airport, models.PROTECT, related_name="crew_first")
|
||||
second_airport = models.ForeignKey(Airport, models.PROTECT, null=True, related_name="crew_second")
|
||||
|
||||
class Address(models.Model):
|
||||
address = models.TextField()
|
||||
zipplace = models.ForeignKey(ZipPlaces, models.PROTECT)
|
||||
roles = models.ManyToManyField(Role, null=True)
|
||||
competences = models.ManyToManyField(Competence, null=True)
|
||||
|
||||
@property
|
||||
def all_competences(self):
|
||||
return self.competences.all().union(*[role.competences.all() for role in self.roles.all()])
|
||||
|
||||
class Phone(models.Model):
|
||||
crew = models.ForeignKey(CrewMember, models.CASCADE)
|
||||
idc = models.ForeignKey(PhoneCode, models.PROTECT, null=True)
|
||||
number = models.CharField(max_length=128)
|
||||
confirmed = models.BooleanField(default=True)
|
||||
priority = models.IntegerField(default=0)
|
||||
|
||||
class Email(models.Model):
|
||||
crew = models.ForeignKey(CrewMember, models.CASCADE)
|
||||
email = models.EmailField()
|
||||
confirmed = models.BooleanField(default=True)
|
||||
priority = models.IntegerField(default=0)
|
|
@ -10,6 +10,13 @@ These models are used by Adonis to return tens of thousands of
|
|||
lines of unneeded data.
|
||||
"""
|
||||
|
||||
class Country(models.Model):
|
||||
code = models.CharField(max_length=16)
|
||||
text = models.CharField(max_length=128)
|
||||
|
||||
class Nationality(models.Model):
|
||||
country = models.ForeignKey(Country, models.PROTECT)
|
||||
|
||||
class Airport(models.Model):
|
||||
city_code = models.CharField(max_length=256, null=True, blank=True)
|
||||
code = models.CharField(max_length=256, null=True, blank=True, unique=True)
|
||||
|
@ -21,13 +28,6 @@ class ZipPlaces(models.Model):
|
|||
postplace = models.CharField(max_length=256)
|
||||
country = models.ForeignKey(Nationality, models.PROTECT)
|
||||
|
||||
class Nationality(models.Model):
|
||||
country = models.ForeignKey(Country, models.PROTECT)
|
||||
|
||||
class Country(models.Model):
|
||||
code = models.CharField(max_length=16)
|
||||
text = models.CharField(max_length=128)
|
||||
|
||||
class PhoneCode(models.Model):
|
||||
code = models.CharField(max_length=16)
|
||||
flag = models.ImageField(null=True, upload_to=get_upload_path)
|
||||
|
|
Loading…
Reference in a new issue