抱歉,我是学生。我有这个场景
class
Sorted
表格(设备 - 警报)没有任何关系:
答案 0 :(得分:0)
有点难以分辨你想做什么,但你可以做一个
的组合# will give all equipment_ids in all alerts
alerted_equipment_ids = Alert.objects.values_list('equipment_id', flat=True).distinct()
# will filter Equipment and give those with alerts
alerted_equipment = Equipment.objects.filter(pk__in=alerted_equipment_ids)
# will get alerts that has a valid equipment-ID
alerts_for_alerted_equipment = Alert.objects.filter(equipment_id__in=alerted_equipment.values_list('pk', flat=True))