You might want to add <code>user.groups.prefetch_related('globalpagepermission_set', 'globalpagepermission_set__sites')</code>