0
我有機型Django的過濾器或沒有記錄
class Product(models.Model):
title = models.CharField(...)
class PropertyType(models.Model):
title = models.CharField(...)
class Property(models.Model):
property_type = models.ForeignKey(PropertyType)
product = models.ForeignKey(Product, related_name='properties')
value = models.CharField(...)
所以,我怎麼就可以篩選產品與一些價值和房產類型的屬性,包括產品,具有相同的房產類型
東西沒有財產這樣
properties = Property.objects.filter(property_type__pk=12, value='anyValue')
products = Product.objects.filter(Q(properties__in=properties)|
Q(NO PROPERTY RECORD WITH PROPERTYTYPE__ID=12 FOR PRODUCT))
笑一個我說什麼,反正如果我的回答幫你,請voteup –