'Attach all the versions and files to the apps.'

@staticmethod
def version_and_file_transformer(apps):

    if (not len(apps)):
        return apps
    ids = set((app.id for app in apps))
    versions = Version.objects.filter(addon__in=ids).select_related('addon')
    vids = [v.id for v in versions]
    files = File.objects.filter(version__in=vids).select_related('version')
    f_dict = dict(((k, list(vs)) for (k, vs) in sorted_groupby(files, 'version_id')))
    for version in versions:
        version.all_files = f_dict.get(version.id, [])
    v_dict = dict(((k, list(vs)) for (k, vs) in sorted_groupby(versions, 'addon_id')))
    for app in apps:
        app.all_versions = v_dict.get(app.id, [])
    return apps
