Skip to content Skip to sidebar Skip to footer

Django, Using "|": Expression Tree Is Too Large (maximum Depth 1000)

I'm trying to concatenate many querysets together. I tried out the marked answer from this question a while back, but that didn't work in my case. I needed to return a queryset not

Solution 1:

I think you want to obtain all the Property objects that have as Function a certain project.

We can query this with:

properties = Property.objects.filter(function__project=project)

This thus is a queryset that contains all property objects for which the function (I assume this is a ForeignKey) has as project (probably again a ForeignKey is the given project). This will result in a single query as well, but you will avoid constructing gigantic unions.

Alternatively, you can do it in two steps, but this would actually make it slower:

# probably less efficient
function_ids = (Function.objects.filter(project=project)
                                .values_list('pk', flat=True))
properties = Properties.object(function_id__in=function_ids)

Post a Comment for "Django, Using "|": Expression Tree Is Too Large (maximum Depth 1000)"