order apilar qoshildi

This commit is contained in:
behruz-dev
2025-11-25 15:22:47 +05:00
parent d356e5321a
commit 8d7738483c
18 changed files with 342 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
from .product import *
from .order_item import *
from .order import *

View File

@@ -0,0 +1,21 @@
from django.db import models
# shared
from core.apps.shared.models import BaseModel, Pharmacy
# accounts
from core.apps.accounts.models import User
class Order(BaseModel):
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='orders')
pharmacy = models.ForeignKey(Pharmacy, on_delete=models.CASCADE, related_name='orders')
total_price = models.DecimalField(decimal_places=2, max_digits=15)
paid_price = models.DecimalField(decimal_places=2, max_digits=15)
advance = models.FloatField()
employee_name = models.CharField(max_length=200)
def __str__(self):
return f'#{self.id} from {self.user.first_name}, total_price - {self.total_price}, paid - {self.paid_price}'

View File

@@ -0,0 +1,15 @@
from django.db import models
# shared
from core.apps.shared.models import BaseModel
class OrderItem(BaseModel):
product = models.ForeignKey('orders.Product', on_delete=models.CASCADE, related_name='order_items')
order = models.ForeignKey('orders.Order', on_delete=models.CASCADE, related_name='order_items')
quantity = models.PositiveIntegerField(default=0)
total_price = models.DecimalField(max_digits=15, decimal_places=2)
def __str__(self):
return f'{self.product.name} - {self.quantity}x'

View File

@@ -0,0 +1,12 @@
from django.db import models
# shared
from core.apps.shared.models import BaseModel
class Product(BaseModel):
name = models.CharField(max_length=200)
price = models.DecimalField(decimal_places=2, max_digits=15)
def __str__(self):
return self.name