来自:https://blog.csdn.net/ding_312/article/details/81264910
class Cart(models.Model): user = models.ForeignKey( MyUser, verbose_name="用户" ) goods = models.ForeignKey( Goods, verbose_name="商品" ) num = models.IntegerField( verbose_name="商品数量" ) is_select = models.BooleanField( default=True, verbose_name="选中状态" ) class Meta: # 联合约束 其中goods和user不能重复 unique_together = ["goods", "user"] # 联合索引, 其中"goods"和"user"联合同步查询,提高效率 index_together = ["user", "goods"]
原文地址:https://www.cnblogs.com/shengulong/p/10320900.html
时间: 2024-11-02 12:15:56