我有一个查询集categories = unipart.categories.all()
,它是unipart对象链接到的所有类别。你知道吗
但是,我想从这个列表中删除顶级类别——也就是那些具有unipart也在其中列出的子类别的类别。你知道吗
或者父类id等于查询集中某个类别id的类别。你知道吗
例如,如果unipart列在: 肉豆蔻(母体=香料)和 香料(母体=食物)
然后我只想包括肉豆蔻——所以基本上我想从queryset中“弹出”香料。你知道吗
最好的方法是什么?我宁愿不用单子。你知道吗
以下是我的模型:
class UniPart (models.Model):
categories=models.ManyToManyField(Category, related_name = 'unipart')
class Category (MPTTModel):
category = models.CharField(max_length=250)
oc_id= models.IntegerField()
parent = TreeForeignKey('self', blank=True, null=True, related_name='children')
def __unicode__(self):
您可以排除具有绑定到此unipart项的子类别的类别:
这里
categorieschild
是子类别的de相关名称。你知道吗相关问题 更多 >
编程相关推荐