Django Exists() / ~Exists() return if there is no matching data?
问题 EDIT: As per schillingt's answer below I have switched to using Case/When: context['db_orders'] = Order.objects.filter( retailer_code=self.object.retailer_code).annotate( in_db=Case(When(Q(Subquery(self.object.suppliers.filter( supplier_code=(OuterRef('supplier_code'))) ), then=Value(True), default=Value(False), output_field=NullBooleanField())))) However I'm now struggling with an errror: FieldError at /retailers/A001/ Cannot resolve expression type, unknown output_field Original question: I