用于判断查询是否返回任何结果的推荐习惯用法是什么?
示例:
orgs = Organisation.objects.filter(name__iexact = 'Fjuk inc')
# If any results
# Do this with the results without querying again.
# Else, do something else...
我想有几种不同的判断方法,但我想知道一个有经验的Django用户会怎么做.
用于判断查询是否返回任何结果的推荐习惯用法是什么?
示例:
orgs = Organisation.objects.filter(name__iexact = 'Fjuk inc')
# If any results
# Do this with the results without querying again.
# Else, do something else...
我想有几种不同的判断方法,但我想知道一个有经验的Django用户会怎么做.
if not orgs:
# Do this...
else:
# Do that...