diff --git a/apps/orders/migrations/0001_initial.py b/apps/orders/migrations/0001_initial.py new file mode 100644 index 0000000..dba1518 --- /dev/null +++ b/apps/orders/migrations/0001_initial.py @@ -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"), + ), + ] diff --git a/apps/orders/models.py b/apps/orders/models.py index 9de469d..72afcba 100644 --- a/apps/orders/models.py +++ b/apps/orders/models.py @@ -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") diff --git a/apps/products/models.py b/apps/products/models.py index d641675..aa80c2e 100644 --- a/apps/products/models.py +++ b/apps/products/models.py @@ -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()