Django中ORM找出内容不为空的数据

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django中ORM找出内容不为空的数据相关的知识,希望对你有一定的参考价值。

在django操作数据库的时候如何找出内容不为空的数据呢?

from django.db.models import Q

class Index(VIew):
    def get(self, request):
        userObj = models.Asset.objects.filter(~Q(asset_id = ‘‘)
        return HttpResponse(‘yes‘)

上面代码中的models.Asset.objects.filter(~Q(nick = ‘‘)则是使用Q函数去找出nick不为空的数据,主要使用~Q

以上是关于Django中ORM找出内容不为空的数据的主要内容,如果未能解决你的问题,请参考以下文章