Closed gevezex closed 3 years ago
I'm a bit confused that file
is a folder :)
But apart from that, I'm not very surprised that this doesn't work. django-tree-queries doesn't understand the more intricate parts of the ORM so that's probably the reason for the failure here.
Maybe all_dossier_files = DossierFile.objects.filter(file__in=f.descendants())
or something would work for you? And if it doesn't maybe this variant is acceptable: all_dossier_files = DossierFile.objects.filter(file__in=list(f.descendants().values_list("id", flat=True))
but of course, if the list of IDs is too large you'll get performance problems. When that happens you can always drop down to raw SQL or something.
Haha that is indeed confusing, but how we use it is that objects in FolderTree can be a file (isfile=True) or folder.
Thnx for your quick answer. I will try it on a big db as locally your second suggestion works well but my test db is not that big. So I will apply it on our big db later on this week.
I am trying to find an intersection between objects of a TreeNode model and the objects of a normal django model who has a FK to this TreeNode model. Models look like this:
What I want is to have an intersection of all the objects of DossierFile's file fields and the descendants of the FolderTree objects. I do it like this:
f_desc is an QuerySet and all_dossier is a TreeQuerySet obviousely. The error I get is:
Any clue what is happening or how to solve this?