首页 > 其他 > 详细

Django model 中设置联合约束和联合索引

时间:2019-01-25 18:13:31      阅读:251      评论:0      收藏:0      [点我收藏+]

来自: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"]

 

Django model 中设置联合约束和联合索引

原文:https://www.cnblogs.com/shengulong/p/10320900.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!