Changed from DO_NOTHING to CASCADE for foreign keys.

Added def __str__ for the models to appear nicely on the admin panel.
parent 291eb2fa
...@@ -15,14 +15,20 @@ class BaseFlavor(models.Model): ...@@ -15,14 +15,20 @@ class BaseFlavor(models.Model):
class Meta: class Meta:
managed = False managed = False
db_table = 'base_flavor' db_table = 'base_flavor'
def __str__(self):
return self.bf_name
class Customer(models.Model): class Customer(models.Model):
customer_id = models.AutoField(primary_key=True) customer_id = models.AutoField(primary_key=True)
customer_name = models.CharField(max_length=255) customer_name = models.CharField(max_length=255)
class Meta: class Meta:
managed = False managed = False
db_table = 'customer' db_table = 'customer'
def __str__(self):
return self.customer_name
class Ingredient(models.Model): class Ingredient(models.Model):
REPLENISHED_STOCK = [ REPLENISHED_STOCK = [
('Y', 'Y'), ('Y', 'Y'),
...@@ -38,6 +44,9 @@ class Ingredient(models.Model): ...@@ -38,6 +44,9 @@ class Ingredient(models.Model):
managed = False managed = False
db_table = 'ingredient' db_table = 'ingredient'
def __str__(self):
return self.ingredient_name
class Size(models.Model): class Size(models.Model):
SIZES = [ SIZES = [
('8', '8'), ('8', '8'),
...@@ -46,12 +55,14 @@ class Size(models.Model): ...@@ -46,12 +55,14 @@ class Size(models.Model):
] ]
size_id = models.AutoField(primary_key=True) size_id = models.AutoField(primary_key=True)
serv_size = models.CharField(max_length=2, choices=SIZES) serv_size = models.CharField(max_length=100, choices=SIZES)
class Meta: class Meta:
managed = False managed = False
db_table = 'size' db_table = 'size'
def __str__(self):
return str(self.serv_size)
class Employee(models.Model): class Employee(models.Model):
employee_id = models.IntegerField(primary_key=True) employee_id = models.IntegerField(primary_key=True)
...@@ -66,7 +77,6 @@ class Employee(models.Model): ...@@ -66,7 +77,6 @@ class Employee(models.Model):
class EmployeeRole(models.Model): class EmployeeRole(models.Model):
ROLES = [ ROLES = [
('Cashier', 'Cashier'), ('Cashier', 'Cashier'),
('Preparation', 'Preparation'), ('Preparation', 'Preparation'),
...@@ -80,7 +90,7 @@ class EmployeeRole(models.Model): ...@@ -80,7 +90,7 @@ class EmployeeRole(models.Model):
role_id = models.AutoField(primary_key=True) role_id = models.AutoField(primary_key=True)
role_date = models.DateField() role_date = models.DateField()
employee = models.ForeignKey(Employee, models.DO_NOTHING) employee = models.ForeignKey(Employee, on_delete=models.CASCADE)
role_description = models.CharField(max_length=20, choices=ROLES) role_description = models.CharField(max_length=20, choices=ROLES)
is_manager = models.CharField(max_length=1, choices=IS_MANAGER) is_manager = models.CharField(max_length=1, choices=IS_MANAGER)
...@@ -93,24 +103,28 @@ class EmployeeRole(models.Model): ...@@ -93,24 +103,28 @@ class EmployeeRole(models.Model):
class Item(models.Model): class Item(models.Model):
item_id = models.AutoField(primary_key=True) item_id = models.AutoField(primary_key=True)
bf = models.ForeignKey(BaseFlavor, models.DO_NOTHING) bf = models.ForeignKey(BaseFlavor, on_delete=models.CASCADE)
ingredient = models.ForeignKey(Ingredient, models.DO_NOTHING) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE)
size = models.ForeignKey(Size, models.DO_NOTHING) size = models.ForeignKey(Size, on_delete=models.CASCADE)
io_quantity = models.IntegerField() io_quantity = models.IntegerField()
total_sales = models.FloatField() total_sales = models.FloatField()
def ingredientname(self): def __str__(self):
return self.ingredient.ingredient_name, self.size.serv_size, self.bf.bf_name return self.bf.bf_name + " with " + self.ingredient.ingredient_name + " || size: " + str(self.size.serv_size)
class Meta: class Meta:
managed = False managed = False
db_table = 'item' db_table = 'item'
class Orders(models.Model): class Orders(models.Model):
order_id = models.AutoField(primary_key=True) order_id = models.AutoField(primary_key=True)
customer_id = models.ForeignKey(Customer, models.DO_NOTHING) customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
item_id = models.ForeignKey(Item, models.DO_NOTHING) item = models.ForeignKey(Item, on_delete=models.CASCADE)
employee_id = models.ForeignKey(Employee, models.DO_NOTHING) employee = models.ForeignKey(Employee,on_delete=models.CASCADE)
order_date = models.DateField() order_date = models.DateField()
class Meta: class Meta:
managed = False managed = False
db_table = 'orders' db_table = 'orders'
\ No newline at end of file verbose_name_plural = "Orders"
def __str__(self):
return self.customer.customer_name + " ordered " + str(self.item) + " from: " + self.employee.employee_name + " on " + str(self.order_date)
\ No newline at end of file
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