gpp/port/models.py
2019-06-02 11:31:53 +02:00

184 lines
4.1 KiB
Python

from django.db import models
from django.db.models import Model, CharField, EmailField, \
DateTimeField, DecimalField, ForeignKey, ManyToManyField
class Address(Model):
address = CharField(max_length=200)
zip_code = CharField(max_length=10)
city = CharField(max_length=200)
country = CharField(max_length=200)
class Person(Model):
name = CharField(max_length=50)
surname = CharField(max_length=50)
nationality = CharField(max_length=200)
email = EmailField(max_length=254)
phone = CharField(max_length=20)
# Foreign keys
address = ForeignKey(Address)
class Company(Model):
name = CharField(max_length=50)
email = EmailField(max_length=200)
phone = CharField(max_length=20)
registration_num = CharField(max_length=50)
# Foreign keys
address = ForeignKey(Address)
class Insurance(Company):
pass
class Boat(Model):
name = CharField(max_length=50)
registration_num = CharField(max_length=20)
length = DecimalField()
beam = DecimalField()
water_draught = DecimalField()
tonnage = DecimalField()
water_tank = DecimalField()
model = CharField(max_length=50)
heating = CharField(max_length=50)
passenger_capacity = IntegerField()
picture = ImageField(upload_to='uploads/', height_field=None, width_field=None, max_length=100)
# Foreign keys
company = ForeignKey(Company)
boat_insurance = ManyToManyField(
Insurance,
through='BoatInsurance',
through_fields=('boat', 'insurance')
)
persons = ManyToManyField(
Person,
through='SailsOn',
through_fields=('boat', 'person')
)
class SailsOn(Model):
boat = ForeignKey(Boat)
person = ForeignKey(Person)
is_captain = BooleanField()
is_crew = BooleanField()
is_owner = BooleanField()
is_guest = BooleanField()
is_pet = BooleanField()
class BoatInsurance(Model)
contract = IntegerField()
date = DateTimeField()
# Foreign keys
insurance = ForeignKey(Insurance)
boat = ForeignKey(Boat)
class Port(Model):
name = CharField(max_length=50)
# Foreign keys
address = ForeignKey(Address)
company = ForeignKey(Company)
employees = ManyToManyField(
Person,
through='Employee',
through_fields=('port', 'person')
)
class Employee(Model):
position = CharField('Job', max_length=20)
# Foreign keys
port = ForeignKey(Port)
person = ForeignKey(Person)
class Dock(Model):
num = CharField(max_length=10)
length = DecimalField()
width = DecimalField()
depth = DecimalField()
# Foreign keys
port = ForeignKey(Port)
class Plug(Model):
num = CharField(max_length=10)
amperage = DecimalField()
voltage = DecimalField()
# Foreign keys
port = ForeignKey(Port)
class Tap(Model):
num = CharField(max_length=10)
# Foreign keys
port = ForeignKey(Port)
class Stay(Model):
arrival = DateTimeField()
departure = DateTimeField()
coming_from = CharField(max_length=200)
going_to = CharField(max_length=200)
# Foreign keys
boat = ForeignKey(Boat)
bill = ForeignKey(Bill)
class PaymentType(Model):
name = CharField(max_length=20)
class Payment(Model):
num = CharField(max_length=40)
date = DateTimeField()
amount = DecimalField()
# Foreign keys
pay_type = ForeignKey(PaymentType)
class Service(Model):
name = CharField(max_length=50)
class BillLine(Model):
quantity = DecimalField()
# Foreign keyks
service = ForeignKey(Service)
bill = ForeignKey(Bill)
class Bill(Model):
num = IntegerField()
date = DateTimeField()
total = DecimalField()
# Foreign keys
payments = ManyToManyField(
Payment,
through='BillPayment',
through_fields=('bill', 'payment')
)
class BillPayment(Model):
amount = DecimalField()
# Foreign keys
bill = ForeignKey(Bill)
payment = ForeignKey(Payment)
class Mooring(Model):
date = DateTimeField()
# Foreign keys
stay = ForeignKey(Stay)
dock = ForeignKey(Dock)
tap = ForeignKey(Tap)
plug = ForeignKey(Plug)