thank you for replying.
MODELS.PY
class Vehicle(models.Model):
STATUS_CHOICES=(
('KIM', 'KIM'),
('Rented Out', 'Rented Out'),
('Available Online', 'Available Online'),
('Available Offline', 'Available Offline'),
('Retired', 'Retired'),
('Under Repair', 'Under Repair'),
('In Store', 'In Store')
)
serial_number = models.CharField(max_length= 100, unique=True)
slug =models.SlugField(max_length=200, db_index=True)
vehicle_category = models.ForeignKey(VehicleCategory,on_delete=models.SET_NULL,related_name='category', null=True)
vehicle_brand = models.ForeignKey(VehicleBrand, on_delete=models.SET_NULL, null=True)
date_of_purchase = models.DateField(blank=True)
date_of_retiring = models.DateField(blank=True, null=True)
purchase_price = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
vehicle_status = models.CharField(max_length=100, choices=STATUS_CHOICES, default='Available Online')
whether_rented_out = models.BooleanField("If Rented Out", default=False)
whether_reserved = models.BooleanField("Reserved", default=False)
qr_code = models.ImageField(
null=True,
blank=True,
width_field="width_field",
height_field= "height_field",
upload_to='qrCode')
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now= True)
objects = models.Manager()#default manager
active = ActiveManager() # custom manager
def __str__(self):
return '%s - %s - %s' % (self.vehicle_category, self.serial_number, self.vehicle_status)
class VehicleCategory(models.Model):
CATEGORY_CHOICES=(
('E-Cycle', 'E-Cycle'),
('E-Scooter', 'E-Scooter')
)
main_category = models.CharField(max_length=15, choices= CATEGORY_CHOICES)
title = models.CharField(unique=True, max_length=200)
image = models.ImageField(
null=True,
blank=True,
width_field="width_field",
height_field= "height_field",
default= 'e-bike.png',
upload_to='category')
width_field = models.IntegerField(default=250)
height_field = models.IntegerField(default=250)
slug =models.SlugField(max_length=200, db_index=True, unique=True)
objects= models.Manager() # the default manager
active = ActiveManager() # custom manager
class Booking(models.Model):
help_text= "Ensure no more than 2 digits after decimal"
BOOKING_CHOICES = [
('Online Booking', 'Online Booking'),
('Offline Booking', 'Offline Booking'),
('Other', 'Other')
]
PAYMENT_CHOICES = [
('Paid', 'Paid'),
('UnPaid', 'UnPaid')
]
PAYMENT_TYPE_CHOICES = [
('Auro Account', 'Auro Account'),
('Auro Card', 'Auro Card'),
('RazorPay', 'RazorPay'),
('Cash', 'Cash'),
('Other', 'Other')
]
booking_id = models.AutoField(primary_key=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, blank=True, null=True)
customer = models.ForeignKey(Customer, on_delete=models.SET_NULL, null=True, blank=True)
start_date = models.DateField(blank=True, null=True)
end_date = models.DateField(blank=True, null=True)
booking_type = models.CharField(max_length=50, choices=BOOKING_CHOICES, default='Online Booking')
payment_status = models.CharField(max_length=10, choices=PAYMENT_CHOICES, default='UnPaid')
amount_paid = models.DecimalField(help_text=help_text,max_digits=7, decimal_places=2, default=0, blank=True)
discount = models.DecimalField(help_text=help_text,max_digits=5, decimal_places=2, default=0, blank=True)
payment_type = models.CharField(max_length=50, choices=PAYMENT_TYPE_CHOICES, null=True, blank=True)
comments = models.TextField(blank=True, null=True)
invoice_number = models.CharField(max_length=100, blank=True, null=True)
total_price = models.IntegerField(blank=True, null=True)
vehicle = models.ManyToManyField(Vehicle, blank=True)
accessory = models.ManyToManyField(Inventory, blank=True)
cart = models.ForeignKey(Cart, on_delete=models.CASCADE)
booked = models.BooleanField(default=False)
transaction_id = models.CharField(max_length=200, null=True, blank=True)
booking_on = models.DateTimeField(auto_now_add=True)
def clean(self):
if self.start_date > self.end_date:
raise ValidationError('Rental ended before start.')
def __str__(self):
return str(self.booking_id)
class CartItem(models.Model):
cart = models.ForeignKey(Cart, on_delete=models.CASCADE, blank=True)
vehiclecategory = models.ForeignKey(VehicleCategory, on_delete=models.CASCADE, related_name='vehiclecategory')
quantity = models.IntegerField(default=1)
accessory = models.ManyToManyField(Inventory,related_name='accessory',blank=True)
accessory_quantity = models.IntegerField(default=0)
class Cart(models.Model):
vehiclecategory = models.ManyToManyField(VehicleCategory,blank=True)
active = models.BooleanField(default=True)