I am using django-treenode to structur certain data. That’s my model:
class Topic(TreeNodeModel):
treenode_display_field = "name"
name = models.CharField(
max_length=50,
)
Let’s assume, my tree looks like this (id
in parenthesis):
'Topic 1' (1)
'Topic 1.1' (2)
'Topic 1.2' (3)
'Topic 2' (4)
'Topic 2.1' (5)
'Topic 2.1.1' (6)
'Topic 2.2' (7)
'Topic 3' (8)
'Topic 3.1' (9)
'Topic 3.2' (10)
…
My goal is to cut out 'Topic 2' (4)
and its descendants. I can filter for tn_ancestors_pks
, but that’s a string (!) containing the pks
, comma separated. So
Topic.objects.exclude(tn_ancestors_pks__contains="4")
excludes also other pks
like “14”, “42” and so on.
How can I filter for single ancestors?