``dev_ids = Device.objects.filter(model__type=DeviceType.unknown).values_list('id', flat=True)`` will be better...