debug and migrations order

This commit is contained in:
Parsa Nazer
2025-01-26 03:17:57 +03:30
parent da1bdc2886
commit 7ffd128e2d
2 changed files with 79 additions and 14 deletions
+62
View File
@@ -0,0 +1,62 @@
# Generated by Django 5.1.2 on 2025-01-25 23:47
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('account', '0009_alter_useraddressmodel_user'),
('product', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='DiscountCode',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('percent', models.DecimalField(decimal_places=2, max_digits=4)),
('quantity', models.PositiveIntegerField()),
('expiration_date', models.DateTimeField()),
],
options={
'verbose_name': 'کد تخفیف',
'verbose_name_plural': 'کد های تخفیف',
},
),
migrations.CreateModel(
name='OrderModel',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='تاریخ سفارش')),
('is_paid', models.BooleanField(default=False, verbose_name='وضعیت پرداخت')),
('status', models.CharField(choices=[('CART', 'در سبد خرید'), ('ADMIN_PENDING', 'در انتظار تایید'), ('PENDING', 'درحال پردازش'), ('POSTED', 'ارسال شده'), ('RECEIVED', 'تحویل شده'), ('CANCELED', 'لغو شده'), ('BACK', 'مرجوع شده')], max_length=20, verbose_name='وضعیت سفارش')),
('address', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='orders', to='account.useraddressmodel')),
('discount_code', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='order.discountcode', verbose_name='کدتخفیف')),
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='orders', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'سفارش',
'verbose_name_plural': 'سفارشات',
},
),
migrations.CreateModel(
name='OrderItemModel',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('quantity', models.SmallIntegerField(verbose_name='تعداد')),
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='product.productmodel', verbose_name='محصول')),
('order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='order.ordermodel')),
],
options={
'verbose_name': 'محصول خریداری شده',
'verbose_name_plural': 'محصولات خریداری شده',
},
),
]
+17 -14
View File
@@ -3,6 +3,23 @@ from account.models import User, UserAddressModel
from product.models import ProductModel from product.models import ProductModel
from django.utils import timezone from django.utils import timezone
class DiscountCode(models.Model):
name = models.CharField(max_length=50)
percent = models.DecimalField(max_digits=4, decimal_places=2)
quantity = models.PositiveIntegerField()
expiration_date = models.DateTimeField()
def __str__(self):
return self.name
class Meta:
verbose_name = 'کد تخفیف'
verbose_name_plural = 'کد های تخفیف'
def is_valid(self):
return self.expiration_date > timezone.now() and self.quantity > 0
class OrderModel(models.Model): class OrderModel(models.Model):
STATUS_CHOICES = [ STATUS_CHOICES = [
('CART', 'در سبد خرید'), ('CART', 'در سبد خرید'),
@@ -70,17 +87,3 @@ class OrderItemModel(models.Model):
return self.quantity * self.product.get_toman_price_after_discount() return self.quantity * self.product.get_toman_price_after_discount()
class DiscountCode(models.Model):
name = models.CharField(max_length=50)
percent = models.DecimalField(max_digits=4, decimal_places=2)
quantity = models.PositiveIntegerField()
expiration_date = models.DateTimeField()
def __str__(self):
return self.name
class Meta:
verbose_name = 'کد تخفیف'
verbose_name_plural = 'کد های تخفیف'
def is_valid(self):
return self.expiration_date > timezone.now() and self.quantity > 0