我在Content表中有以下列作为名称和标记。
从以下django查询中可以找到名为column的标记中包含None
值的标记,而不使用for循环而不使用.exclude()
newobj = Content.objects.filter(name="Harry")
boolval = if tag has or not not None value
答案 0 :(得分:0)
是的,请使用__isnull [0]
Content.objects.filter(name="Harry", tag__isnull=True)
[0] https://docs.djangoproject.com/en/dev/ref/models/querysets/#isnull
扩展此:
我们不能从newobj做到这一点 - Rajeev
.filter()返回一个查询集。
newobj = Content.objects.filter(name="Harry")
boolval = newobj.exists(tag__isnull=True)
如果Harry有空标记,这将返回true / false(按存在)。