django 设计一套软件销售的model,生成报价表,确认后生成订单,通过订单生成合同
时间: 2024-03-03 10:47:32 浏览: 43
好的,以下是一个简单的软件销售的 Django Model 设计,包括报价表、订单和合同:
```python
from django.db import models
class Product(models.Model):
name = models.CharField(max_length=100)
description = models.TextField()
price = models.DecimalField(max_digits=8, decimal_places=2)
def __str__(self):
return self.name
class Customer(models.Model):
name = models.CharField(max_length=100)
email = models.EmailField()
phone = models.CharField(max_length=20, blank=True, null=True)
address = models.TextField(blank=True, null=True)
def __str__(self):
return self.name
class Quotation(models.Model):
customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.IntegerField(default=1)
created_at = models.DateTimeField(auto_now_add=True)
total_price = models.DecimalField(max_digits=8, decimal_places=2)
def __str__(self):
return f"{self.customer.name} - {self.product.name}"
class Order(models.Model):
customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.IntegerField(default=1)
created_at = models.DateTimeField(auto_now_add=True)
total_price = models.DecimalField(max_digits=8, decimal_places=2)
def __str__(self):
return f"{self.customer.name} - {self.product.name}"
class Contract(models.Model):
order = models.ForeignKey(Order, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
content = models.TextField()
def __str__(self):
return f"{self.order.customer.name} - {self.order.product.name}"
```
上面的代码定义了四个模型,`Product`、`Customer`、`Quotation`、`Order` 和 `Contract`。`Product` 模型表示销售的产品,包含了名称、描述和价格。`Customer` 模型表示客户,包含了姓名、电子邮件、电话和地址。
`Quotation` 模型表示报价单,包含了客户、产品、数量、报价单创建时间和总价。`Order` 模型表示订单,包含了客户、产品、数量、订单创建时间和总价。`Quotation` 和 `Order` 模型的区别在于,`Quotation` 是客户询问报价后生成的,需要客户确认后才可以生成订单;而 `Order` 是客户确认后生成的。
`Contract` 模型表示合同,包含了订单、合同创建时间和合同内容。合同是根据客户确认的订单生成的。
你可以根据你的具体需求来添加其他的模型,例如支付信息等等。