1

I expect a behaviour I'm not obtaining. Consider this example model:

class Node(models.Model):
    name = models.CharField(max_length=30)  # Verbose for readability

class SpecialNode(Node):
   other_attr = models.CharField(max_length=30)

class Edge(models.Model):
    nodes = models.ManyToManyField(Node, related_name="edges")

I have a given node (that is not Special), and I want to know which Edges doesn't (or does) connect with a SpecialNode.

If I do this, works:

# All the edges except those which have a node that is a SpecialNode
Edge.objects.filter(node__id=1).exclude(nodes__specialnode__isnull=False)

Tho... this doesn't work, returns all the edges of the node instead.

Node.objects.get(id=1).edges.exclude(nodes__specialnode__isnull=False)

I don't know what I'm missing or missunderstanding, but I expect a queryset of edges with both sentences.

0 Answers0