Skip to content
Merged
Show file tree
Hide file tree
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
Binary file modified essenza/db.sqlite3
Binary file not shown.
7 changes: 7 additions & 0 deletions essenza/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pip install -r requirements.txt && \
python manage.py flush --noinput && \
python manage.py migrate --noinput && \
# python manage.py collectstatic --noinput && \
python manage.py loaddata user/sample/sample.json && \
python manage.py loaddata product/sample/sample.json && \
python manage.py loaddata order/sample/sample.json
11 changes: 8 additions & 3 deletions essenza/order/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ class Status(models.TextChoices):

class Order(models.Model):
user = models.ForeignKey('user.Usuario', on_delete=models.CASCADE, related_name='orders')
adress = models.CharField(max_length=255)
address = models.CharField(max_length=255)
placed_at = models.DateTimeField(auto_now=True)
total_price = models.DecimalField(max_digits=10, decimal_places=2)
status = models.CharField(max_length=10, choices=Status.choices, default=Status.PENDING)

@property
def total_price(self):
total = 0
for product in self.order_products.all():
total += product.quantity * product.product.price
return total

def __str__(self):
return f"Order {self.id} by {self.user.email}"

Expand All @@ -21,7 +27,6 @@ class OrderProduct(models.Model):
order = models.ForeignKey('order.Order', on_delete=models.CASCADE, related_name='order_products')
product = models.ForeignKey('product.Product', on_delete=models.CASCADE, related_name='product_orders')
quantity = models.IntegerField()
unity_price = models.DecimalField(max_digits=10, decimal_places=2)

def __str__(self):
return f"{self.quantity} of {self.product.name} in order {self.order.id}"
151 changes: 151 additions & 0 deletions essenza/order/sample/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
[
{
"model": "order.order",
"pk": 1,
"fields": {
"user": 1,
"address": "Calle Gran Vía, 23, Madrid, 28013",
"placed_at": "2024-02-12T10:45:00Z",
"status": "pending"
}
},
{
"model": "order.order",
"pk": 2,
"fields": {
"user": 2,
"address": "Avenida de la Constitución, 8, Sevilla, 41001",
"placed_at": "2024-03-01T15:10:00Z",
"status": "paid"
}
},
{
"model": "order.order",
"pk": 3,
"fields": {
"user": 3,
"address": "Carrer de Pau Claris, 60, Barcelona, 08010",
"placed_at": "2024-03-20T19:25:00Z",
"status": "shipped"
}
},
{
"model": "order.order",
"pk": 4,
"fields": {
"user": 1,
"address": "Calle Alcalá, 120, Madrid, 28009",
"placed_at": "2024-04-05T09:00:00Z",
"status": "pending"
}
},
{
"model": "order.order",
"pk": 5,
"fields": {
"user": 2,
"address": "Plaza Nueva, 10, Bilbao, 48001",
"placed_at": "2024-04-22T12:15:00Z",
"status": "shipped"
}
},
{
"model": "order.orderproduct",
"pk": 1,
"fields": {
"order": 1,
"product": 1,
"quantity": 2
}
},
{
"model": "order.orderproduct",
"pk": 2,
"fields": {
"order": 1,
"product": 18,
"quantity": 1
}
},
{
"model": "order.orderproduct",
"pk": 3,
"fields": {
"order": 2,
"product": 5,
"quantity": 3
}
},
{
"model": "order.orderproduct",
"pk": 4,
"fields": {
"order": 2,
"product": 14,
"quantity": 2
}
},
{
"model": "order.orderproduct",
"pk": 5,
"fields": {
"order": 3,
"product": 3,
"quantity": 1
}
},
{
"model": "order.orderproduct",
"pk": 6,
"fields": {
"order": 3,
"product": 9,
"quantity": 2
}
},
{
"model": "order.orderproduct",
"pk": 7,
"fields": {
"order": 3,
"product": 10,
"quantity": 1
}
},
{
"model": "order.orderproduct",
"pk": 8,
"fields": {
"order": 4,
"product": 11,
"quantity": 2
}
},
{
"model": "order.orderproduct",
"pk": 9,
"fields": {
"order": 4,
"product": 15,
"quantity": 1
}
},
{
"model": "order.orderproduct",
"pk": 10,
"fields": {
"order": 5,
"product": 7,
"quantity": 4
}
},
{
"model": "order.orderproduct",
"pk": 11,
"fields": {
"order": 5,
"product": 20,
"quantity": 2
}
}
]
5 changes: 3 additions & 2 deletions essenza/product/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ class Category(models.TextChoices):
class Product(models.Model):
name = models.CharField(max_length=255)
description = models.TextField()
categoria = models.CharField(max_length=20, choices=Category.choices)
category = models.CharField(max_length=20, choices=Category.choices)
brand = models.CharField(max_length=255)
price = models.DecimalField(max_digits=10, decimal_places=2)
foto = models.ImageField(upload_to='profile_pics/', null=True, blank=True)
photo = models.ImageField(upload_to='profile_pics/', null=True, blank=True)
stock = models.IntegerField()
is_active = models.BooleanField(default=False)


def __str__(self):
return self.name

Loading