私は、特定の関連オブジェクトを持っている、または持っていないすべてのアイテムをリストできるようにするdjangoクエリを求めています。
たとえば、モデルがある場合:
def Customer(Model):
name = CharField(...)
...
def Order(Model):
customer = ForeignKey(Customer)
さて、「すべての顧客に注文を与え、逆に、すべての顧客に注文を与えない」とはどうすればよいでしょうか。
私がこれまでに持っているもの(これは機能しません)はこれです:
withords = model.objects.all().annotate(orders=Count('order')).filter(orders__gt=0)
without = model.objects.all().annotate(orders=Count('order')).filter(orders__lt=1)
何か案は?