[Answer]-How can I filter a query by a GenericForeignKey-Field using another query as possible values?

1👍

You can get the model of the queryset and then filter Point for that particular content type:

@register.simple_tag()
def get_points_for_query(q):
    ct = ContentType.objects.get_for_model(q.model)
    return Point.objects.filter(content_type=ct, object_id__in=q) \
                        .prefetch_related('content_obj').order_by('pk')

I’m not sure in the object_id__in=q clause. If it will not work then try:

object_id__in=q.values_list('id', flat=True)

This should work fine.

Leave a comment