chore: add subtotal to attributes of Booking_AddItem

parent 74fd40aa
......@@ -10,7 +10,7 @@ class PassengerAdmin(admin.ModelAdmin):
class BookingAdmin(admin.ModelAdmin):
model = Booking
list_display = ('Booking_ID', 'Booking_Date', 'Total_Cost', 'Passenger')
list_display = ('Booking_ID', 'Booking_Date', 'Passenger', 'Total_Cost')
class Sched_CrewAdmin(admin.ModelAdmin):
model = Sched_Crew
......@@ -42,7 +42,7 @@ class Booking_SchedAdmin(admin.ModelAdmin):
class Booking_AddItemAdmin(admin.ModelAdmin):
model = Booking_AddItem
list_display = ('Booking_ID', 'AddItem_Desc', 'Quantity')
list_display = ('Booking_ID', 'AddItem_Desc', 'Quantity', 'subtotal')
class PilotAdmin(admin.ModelAdmin):
model = Pilot
......
from django.db import models
from django.http import Http404
from django.core.validators import RegexValidator,EmailValidator
# Create your models here.
......@@ -34,9 +35,13 @@ class Passenger(models.Model):
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.CharField(max_length=100)
Total_Cost = models.IntegerField(blank=True, default=0,null=False)
Passenger = models.ForeignKey(Passenger, on_delete=models.CASCADE)
def __str__(self):
return str(self.Booking_ID)
class Additional_Item(models.Model):
Description = models.CharField(max_length=50, primary_key=True, editable=True, unique=True)
Item_Cost = models.IntegerField(default=0)
......@@ -52,6 +57,15 @@ class Booking_AddItem(models.Model):
AddItem_Desc = models.ForeignKey(Additional_Item, on_delete=models.CASCADE)
Quantity = models.IntegerField(default=0)
@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
class City(models.Model):
Airport_Code = models.AutoField(primary_key=True, editable=False, unique=True)
Airport_name = models.CharField(max_length=50)
......
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