django 设计一套软件销售的model
时间: 2024-01-30 14:10:58 浏览: 24
好的,以下是一个简单的软件销售的 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 Order(models.Model):
customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.IntegerField(default=1)
order_date = 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}"
```
上面的代码定义了三个模型,`Product`、`Customer` 和 `Order`。`Product` 模型表示销售的产品,包含了名称、描述和价格。`Customer` 模型表示客户,包含了姓名、电子邮件、电话和地址。`Order` 模型表示客户购买产品的订单信息,包含了客户、产品、数量、下单日期和总价。
`Order` 模型中的 `customer` 和 `product` 字段是外键,分别与 `Customer` 和 `Product` 模型建立关联。`quantity` 字段表示客户购买的产品数量,`order_date` 字段表示订单的下单日期,`total_price` 字段表示订单的总价。
你可以根据你的具体需求来添加其他的模型,例如支付信息等等。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)