Commit 3472aa69 authored by Patricia Isabella Nava's avatar Patricia Isabella Nava
parents a84dc1b9 0cc0c69a
......@@ -42,7 +42,7 @@ class Booking_SchedAdmin(admin.ModelAdmin):
class Booking_AddItemAdmin(admin.ModelAdmin):
model = Booking_AddItem
list_display = ('Booking_ID', 'AddItem_Desc', 'Quantity', 'subtotal')
list_display = ('Booking_ID', 'AddItem_Desc', 'Quantity', 'Subtotal')
class PilotAdmin(admin.ModelAdmin):
model = Pilot
......
# Generated by Django 4.0.4 on 2022-12-01 05:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('booking', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='booking',
name='Additional_Item',
field=models.ManyToManyField(through='booking.Booking_AddItem', to='booking.additional_item'),
),
]
# Generated by Django 4.0.4 on 2022-12-01 05:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('booking', '0002_booking_additional_item'),
]
operations = [
migrations.AddField(
model_name='booking_additem',
name='Subtotal',
field=models.IntegerField(default=0, editable=False),
),
]
# Generated by Django 4.0.4 on 2022-12-01 05:51
import booking.models
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('booking', '0003_booking_additem_subtotal'),
]
operations = [
migrations.AlterField(
model_name='booking_additem',
name='Subtotal',
field=models.IntegerField(default=booking.models.Booking_AddItem.subtotal, editable=False),
),
]
# Generated by Django 4.0.4 on 2022-12-01 06:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('booking', '0004_alter_booking_additem_subtotal'),
]
operations = [
migrations.AlterField(
model_name='booking_additem',
name='Quantity',
field=models.IntegerField(default=1),
),
migrations.AlterField(
model_name='booking_additem',
name='Subtotal',
field=models.IntegerField(default=0, editable=False),
),
]
# Generated by Django 4.0.4 on 2022-12-01 07:20
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('booking', '0005_alter_booking_additem_quantity_and_more'),
]
operations = [
migrations.AddField(
model_name='booking',
name='Flight_Sched',
field=models.ManyToManyField(through='booking.Booking_Sched', to='booking.schedule'),
),
migrations.AlterField(
model_name='booking',
name='Total_Cost',
field=models.IntegerField(blank=True, default=0, editable=False),
),
migrations.AlterField(
model_name='schedule',
name='Flight_Cost',
field=models.IntegerField(default=0),
),
]
......@@ -32,14 +32,24 @@ class Passenger(models.Model):
return self.First_Name + ' ' + self.Last_Name
class Booking(models.Model):
Booking_ID = models.AutoField(primary_key=True, editable=False, unique=True)
Booking_Date = models.DateField(null=True, blank=True)
Total_Cost = models.IntegerField(blank=True, default=0,null=False)
Passenger = models.ForeignKey(Passenger, on_delete=models.CASCADE)
class City(models.Model):
Airport_Code = models.AutoField(primary_key=True, editable=False, unique=True)
Airport_name = models.CharField(max_length=50)
City_Name = models.CharField(max_length=50)
Country = models.CharField(max_length=50)
def __str__(self):
return str(self.Booking_ID)
return self.Airport_name + ' (' + self.Country + ')'
class Flight(models.Model):
Flight_ID = models.AutoField(primary_key=True, editable=False, unique=True)
Flight_Code = models.CharField(max_length=6)
Origin_Airport = models.ForeignKey(City, on_delete=models.CASCADE, related_name='origin')
Destination_Airport = models.ForeignKey(City, on_delete=models.CASCADE, related_name='destination')
def __str__(self):
return self.Flight_Code + ' (' + self.Origin_Airport.City_Name + ' to ' + self.Destination_Airport.City_Name + ')'
class Additional_Item(models.Model):
......@@ -49,31 +59,78 @@ class Additional_Item(models.Model):
def __str__(self):
return self.Description
class Schedule(models.Model):
Sched_Code = models.AutoField(primary_key=True, editable=False, unique=True)
Flight_Date = models.DateField(null=True, blank=True)
Departure_Time = models.TimeField(null=True, blank=True)
Arrival_Time = models.TimeField(null=True, blank=True)
Duration = models.CharField(max_length=50)
Flight_Cost = models.IntegerField(default=0)
Flight_Code = models.ForeignKey(Flight, on_delete=models.CASCADE)
class Booking(models.Model):
Booking_ID = models.AutoField(primary_key=True, editable=False, unique=True)
Booking_Date = models.DateField(null=True, blank=True)
Total_Cost = models.IntegerField(blank=True, default=0, null=False, editable=False)
Passenger = models.ForeignKey(Passenger, on_delete=models.CASCADE)
Additional_Item = models.ManyToManyField(Additional_Item, through='Booking_AddItem')
Flight_Sched = models.ManyToManyField(Schedule, through='Booking_Sched')
def __str__(self):
return str(self.Booking_ID)
def flightCost(self):
costs = []
for x in self.Flight_Sched.all():
costs.append(x.Flight_Cost)
total = sum(costs)
return total
def addCost(self):
costs = []
add_item = Booking_AddItem.objects.filter(Booking_ID=self.Booking_ID)
for x in add_item:
costs.append(x.Subtotal)
total = sum(costs)
return total
def save(self, *args, **kwargs):
if not self.Booking_ID:
super(Booking, self).save(*args, **kwargs)
self.Total_Cost = self.flightCost() + self.addCost()
super(Booking, self).save(*args, **kwargs)
class Booking_AddItem(models.Model):
class Meta:
unique_together = ('Booking_ID', 'AddItem_Desc')
Booking_ID = models.ForeignKey(Booking, on_delete=models.CASCADE)
AddItem_Desc = models.ForeignKey(Additional_Item, on_delete=models.CASCADE)
Quantity = models.IntegerField(default=0)
Quantity = models.IntegerField(default=1)
Subtotal = models.IntegerField(default=0, editable=False)
@property
def subtotal(self):
add_item = Additional_Item.objects.get(Description = self.AddItem_Desc)
itemcost = add_item.Item_Cost
subtotal = itemcost*self.Quantity
return subtotal
def save(self, *args, **kwargs):
self.Subtotal= self.subtotal()
super(Booking_AddItem, self).save(*args, **kwargs)
class City(models.Model):
Airport_Code = models.AutoField(primary_key=True, editable=False, unique=True)
Airport_name = models.CharField(max_length=50)
City_Name = models.CharField(max_length=50)
Country = models.CharField(max_length=50)
def __str__(self):
return self.Airport_name + ' (' + self.Country + ')'
class Booking_Sched(models.Model):
class Meta:
unique_together = ('Booking_ID', 'Sched_Code')
Booking_ID = models.ForeignKey(Booking, on_delete=models.CASCADE)
Sched_Code = models.ForeignKey(Schedule, on_delete=models.CASCADE)
class Crew_Member(models.Model):
Employee_ID = models.AutoField(primary_key=True, editable=False, unique=True)
......@@ -128,23 +185,6 @@ class Flight_Attendant(models.Model):
def __str__(self):
return self.Employee_ID.First_Name + ' ' + self.Employee_ID.Last_Name + ' (' + self.Assigned_Class + ')'
class Flight(models.Model):
Flight_ID = models.AutoField(primary_key=True, editable=False, unique=True)
Flight_Code = models.CharField(max_length=6)
Origin_Airport = models.ForeignKey(City, on_delete=models.CASCADE, related_name='origin')
Destination_Airport = models.ForeignKey(City, on_delete=models.CASCADE, related_name='destination')
def __str__(self):
return self.Flight_Code + ' (' + self.Origin_Airport.City_Name + ' to ' + self.Destination_Airport.City_Name + ')'
class Schedule(models.Model):
Sched_Code = models.AutoField(primary_key=True, editable=False, unique=True)
Flight_Date = models.DateField(null=True, blank=True)
Departure_Time = models.TimeField(null=True, blank=True)
Arrival_Time = models.TimeField(null=True, blank=True)
Duration = models.CharField(max_length=50)
Flight_Cost = models.CharField(max_length=50)
Flight_Code = models.ForeignKey(Flight, on_delete=models.CASCADE)
class Sched_Crew(models.Model):
class Meta:
......@@ -152,10 +192,3 @@ class Sched_Crew(models.Model):
Sched_Code = models.ForeignKey(Schedule, on_delete=models.CASCADE)
Employee_ID = models.ForeignKey(Crew_Member, on_delete=models.CASCADE)
\ No newline at end of file
class Booking_Sched(models.Model):
class Meta:
unique_together = ('Booking_ID', 'Sched_Code')
Booking_ID = models.ForeignKey(Booking, on_delete=models.CASCADE)
Sched_Code = models.ForeignKey(Schedule, on_delete=models.CASCADE)
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment