我想要從掃描的last 100
數據包中獲取所有包含status = 'open'
的數據包的計數。Django過濾器查詢
目前我做的順序搜索,即
packet_obj = Packets.objects.all().oreder_by('-time')[:100] # getting the last 100 packets
for packets in packet_obj:
if packets.status == 'open' : count += 1 # comparing the status
有直達單查詢得到這個算不算?
爲什麼不能你只是做'QS = Packets.objects.order_by ('-time')[:100]'和'len(qs.filter(status ='open')[:100])' – karthikr