判断django中的orm为空

 

result= Booking.objects.filter()
 
 
#方法一 .exists()
if result.exists():
    print "QuerySet has Data"
else:
    print "QuerySet is empty"
#方法二 .count()==0
if result.count() == 0:
    print "empty"
#方法三
if result:
    print "QuerySet has Data"
else:
    print "QuerySet is empty"
 
总结:
QuerySet.exists() > QuerySet.count()==0 > QuerySet

 

posted @ 2019-06-10 11:37  风来风往风伤(TiAmo)  阅读(506)  评论(0编辑  收藏  举报