rohitjain-rj / django-tagging

Automatically exported from code.google.com/p/django-tagging
Other
0 stars 0 forks source link

Suggested util method: calculate_cloud_from_models #199

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I wrote a quick little util method that combines tag clouds from multiple
models into a single cloud.

I'm not sure if other people would find this useful, but I would have liked
to have it included in django-tagging.

def calculate_cloud_from_models(*args):
    from tagging.models import Tag 
    cloud = Tag._default_manager.cloud_for_model(args[0])
    for model in args[1:]:
        for tag in Tag._default_manager.cloud_for_model(model):
            if tag in cloud:
                cloud[cloud.index(tag)].count+=tag.count
            else:
                cloud.append(tag)
    return calculate_cloud(cloud)

Original issue reported on code.google.com by phillipm...@gmail.com on 4 Jun 2009 at 8:14