django model新建空querySet:models.Atable.objects.none()

queryset有时需要一个空queryset,用于后续用循环并集的初值,举例如下

tables = DataFlowTable.objects.filter(data_status=0)
logs = DataFlowTableTransLog.objects.filter(data_status=0)
schemas = logs.values_list('source_schema', flat=True).distinct()
# 建一个空queryset,作为后续循环做并集的初值
s_tables = tables.none()
for schema in schemas:
    s_logs = logs.filter(source_schema=schema)
    s_tables |= tables.filter(name__in=s_logs.values('source_table'))
return s_tables

你可能感兴趣的:(django)