使用AND条件Django筛选具有多个值的同一列



sql查询如下所示。

选择*FROM catalogy_productcategory WHERE(category_id=40(和(product_id=7(

实际上我找到了解决方案
pc=ProductCategory.objects.filter(Q(类别id=40(和Q(类别id=44((

您为它们定义了模型类吗?

class catalogue_productcategory(model.Model):
#define your desire fields
category = model.ForeignKey(Category)
product = model.ForeignKey(Product)

catalogue_productcategory.objects.filter(category__id=40, product__id=7)

最新更新