views:

14

answers:

0

I have a comment model with a GenericForeignKey. The comments key to content which has a site assignment; they themselves have none. This becomes a problem when certain users should only be able to see comments that belong to sites they can see; that is, comments which point to content that is assigned to a site they can see.

Right now, in the admin, I am generating the list with SQL which is fairly 'cheap' and runs quickly. I don't have much choice otherwise since the ORM can't do the necessary joins on all the content types' sites tables that the content has. The problem is that the admin's queryset() method that returns the actual list demands just that, a QuerySet. Right now I am converting the results of my SQL into a Queryset by running an objects.filter(id__in = (results of my SQL)) statement, but that performs poorly with large datasets.

Is there a better way to do this? I see Django 1.2 has an objects.raw() function that may do it, but I haven't found if the admin will accept the RawQuerySet model that it returns.