📅  最后修改于: 2023-12-03 15:31:02.248000             🧑  作者: Mango
该数据库表是一个关联表,用于连接商品信息表和商品类别表。本表中的商品类别ID(goodscategory_id)与商品类别表(goods_goodscategory)中的主键ID(id)相对应,而商品信息表(goods_goodsinfo)中的主键ID(id)则是本表的外键(fk_goods_goodscategory_id)。
+--------------+ +--------------------+ +----------------------+
| | | | | |
| goods_info | | goods_goodsinfo_cag | | goods_goodscategory |
| | | | | |
+--------------+ +--------------------+ +----------------------+
+ + +
| | |
v | +---------------+--+
+--------------+ goods_id | | |
| | +-------------->+ goodscategory_id | +----------+-------+
| goods_goodsinfo_cag | | | |
| | v v | goods_goodscategory |
+--------------+ +------+ +-------+ |
| id | | id | |
| |<----------------+ +------------------+
+------+
# 通过外键查询特定商品类别下的所有商品信息
goods_list = GoodsInfo.objects.filter(goods_goodsinfo_cag__goodscategory_id=1)
# 通过商品类别ID查询对应的商品信息
goods_list = GoodsInfo.objects.filter(goods_goodsinfo_cag__goodscategory__id=1)