我在Content表中有以下列作为name和tag。
在下面的django查询中,有没有办法在不使用None循环而不使用.exclude()的情况下找到名为column的标记的值
newobj = Content.objects.filter(name="Harry")
boolval = if tag has or not not None value发布于 2012-08-20 03:12:57
是,使用__isnull
Content.objects.filter(name="Harry", tag__isnull=True)在此基础上进行扩展:
我们不能从新的对象开始做这个吗
.filter()返回一个查询集。
newobj = Content.objects.filter(name="Harry")
boolval = newobj.exists(tag__isnull=True)如果存在带有空标签的Harry,这将返回true/false (由exists)。
https://stackoverflow.com/questions/12029159
复制相似问题