【发布时间】:2020-09-15 20:34:24
【问题描述】:
我有一点代码如下:
for prop in Property.objects.all():
for platform_device in prop.platformdevice_set.all():
if platform_device.platform == cur_platform:
if platform_device.applicable_devices.filter(name=cur_device).exists():
if platform_device.applicable_events.filter(name=cur_event).exists():
print("Found my correct even and need to continue processing.")
else:
for group in platform_device.event_group.all():
if group.applicable_events.filter(name=cur_event).exists():
print("Found my correct even and need to continue processing.")
它有点乱,但到目前为止它正在工作。我被困在这部分:
if platform_device.applicable_events.filter(name=cur_event).exists():
print("Found my correct even and need to continue processing.")
else:
for group in platform_device.event_group.all():
if group.applicable_events.filter(name=cur_event).exists():
print("Found my correct even and need to continue processing.")
基本上我正在做的是检查platform_device.applicable_events 以检查其中是否包含我的cur_event。如果是,那么我需要从那时起继续处理。
其他
我将查看 event_group(它只是一组事件)并检查 cur_event 是否在其中一个组中,然后继续处理。
我的问题是,我怎样才能让这两种途径最终出现在同一个地方。我只是想防止在这两个位置使用相同的代码。
【问题讨论】:
标签: python django django-views django-queryset