Skip to content

Commit

Permalink
Add order migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ByJIaT committed Aug 11, 2023
1 parent 54ee5f0 commit 2f49498
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 5 deletions.
126 changes: 126 additions & 0 deletions apps/orders/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Generated by Django 4.1 on 2023-08-11 15:57

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("products", "0001_initial"),
]

operations = [
migrations.CreateModel(
name="Order",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"status",
models.CharField(
choices=[
("CR", "Created"),
("UP", "Updated"),
("PA", "Paid"),
("TR", "In_transit"),
("CO", "Completed"),
("CA", "Canceled"),
("RE", "Returned"),
],
default="CR",
max_length=2,
verbose_name="Order status",
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="customer",
to=settings.AUTH_USER_MODEL,
verbose_name="Order owner",
),
),
],
options={
"verbose_name": "Order",
"verbose_name_plural": "Orders",
},
),
migrations.CreateModel(
name="OrderProduct",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"quantity",
models.PositiveIntegerField(
verbose_name="Product quantity in order"
),
),
(
"discount",
models.DecimalField(
decimal_places=2, max_digits=4, verbose_name="Product discount"
),
),
(
"order",
models.OneToOneField(
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="orders",
to="orders.order",
verbose_name="Order",
),
),
(
"product",
models.ForeignKey(
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="orders",
to="products.product",
verbose_name="Product in order",
),
),
],
options={
"verbose_name": "OrderProduct",
"verbose_name_plural": "OrderProducts",
},
),
migrations.AddIndex(
model_name="orderproduct",
index=models.Index(fields=["order"], name="orders_orde_order_i_d30f9b_idx"),
),
migrations.AddConstraint(
model_name="orderproduct",
constraint=models.UniqueConstraint(
fields=("order", "product"),
name="orders_orderproduct_order_product_uniq",
),
),
migrations.AddIndex(
model_name="order",
index=models.Index(fields=["user"], name="orders_orde_user_id_a87c6f_idx"),
),
]
16 changes: 13 additions & 3 deletions apps/orders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,22 @@ def __str__(self):


class OrderProduct(models.Model):
order = models.OneToOneField(Order, on_delete=models.DO_NOTHING, related_name="orders", verbose_name=_("Order"))
order = models.OneToOneField(
Order,
on_delete=models.DO_NOTHING,
related_name="orders",
verbose_name=_("Order"),
)
product = models.ForeignKey(
Product, on_delete=models.DO_NOTHING, related_name="orders", verbose_name=_("Product in order")
Product,
on_delete=models.DO_NOTHING,
related_name="orders",
verbose_name=_("Product in order"),
)
quantity = models.PositiveIntegerField(verbose_name=_("Product quantity in order"))
discount = models.DecimalField(max_digits=4, decimal_places=2, verbose_name=_("Product discount"))
discount = models.DecimalField(
max_digits=4, decimal_places=2, verbose_name=_("Product discount")
)

class Meta:
verbose_name = _("OrderProduct")
Expand Down
8 changes: 6 additions & 2 deletions apps/products/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ class Product(SoftDeleteMixin, BaseModel):
brand = models.CharField(max_length=255, verbose_name=_("Product brand"))
price = models.DecimalField(max_digits=11, decimal_places=2, verbose_name=_("Product price"))
wholesale_quantity = models.PositiveIntegerField(verbose_name=_("Product wholesale quantity"))
video = models.FileField(upload_to=get_product_directory_path, null=True, verbose_name=_("Product video"))
video = models.FileField(
upload_to=get_product_directory_path, null=True, verbose_name=_("Product video")
)
quantity_in_stock = models.PositiveIntegerField(verbose_name=_("Products quantity in stock"))
description = models.TextField(verbose_name=_("Product description"))
manufacturer_country = models.CharField(max_length=255, verbose_name=_("Product manufacturer country"))
manufacturer_country = models.CharField(
max_length=255, verbose_name=_("Product manufacturer country")
)

objects = ProductManager()

Expand Down

0 comments on commit 2f49498

Please sign in to comment.