Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Create your models here.

# Users that will be registered
class Customer(models.Model):
user = models.OneToOneField(User, null=True, blank=True, on_delete=models.CASCADE)
name = models.CharField(max_length=200, null=True)
Expand All @@ -11,6 +12,7 @@ class Customer(models.Model):
def __str__(self):
return self.name

# Products available on the website

class Product(models.Model):
name = models.CharField(max_length=200)
Expand All @@ -29,6 +31,8 @@ def imageURL(self):
url = ''
return url

# all the Products ordered By a specific user

class Order(models.Model):
customer = models.ForeignKey(Customer, on_delete=models.SET_NULL, null=True, blank=True)
date_ordered = models.DateTimeField(auto_now_add=True)
Expand Down Expand Up @@ -59,6 +63,8 @@ def get_cart_items(self):
total = sum([item.quantity for item in orderitems])
return total

# retrieved a certain item in the cart

class OrderItem(models.Model):
product = models.ForeignKey(Product, on_delete=models.SET_NULL, null=True)
order = models.ForeignKey(Order, on_delete=models.SET_NULL, null=True)
Expand All @@ -70,6 +76,8 @@ def get_total(self):
total = self.product.price * self.quantity
return total

# User's address

class ShippingAddress(models.Model):
customer = models.ForeignKey(Customer, on_delete=models.SET_NULL, null=True)
order = models.ForeignKey(Order, on_delete=models.SET_NULL, null=True)
Expand All @@ -80,4 +88,4 @@ class ShippingAddress(models.Model):
date_added = models.DateTimeField(auto_now_add=True)

def __str__(self):
return self.address
return self.address