I have 3 models in my django app

```
class Company(models.Model):

    name = models.CharField(_("Name"), max_length = 100, blank = True, null = True)
    address = models.CharField(_("Address"), max_length = 300, blank = True, null = True)

class WebSite(models.Model):

    WEBSITE_TYPE_CHOICES = (
        ('Google+', 'Google+'),
        ('Facebook', 'Facebook'),
        ('Orkut', 'Orkut'),
    )
    user = models.ForeignKey(User)
    website = models.URLField(blank = True, null = True)
    website_type = models.CharField(max_length = 15, choices = WEBSITE_TYPE_CHOICES, default = 'Google+')
    company = models.ForeignKey(Company, null=True, blank=True)

class Review(models.Model):

    rating = models.FloatField(blank = True, null = True) 
    review = models.TextField(blank = True, null = True)
    company = models.ForeignKey(Company, null=True, blank=True)
    website = models.ForeignKey(Website, null=True, blank=True)

```

I want to display my data such as 

CompanyA:

1. Google - 5 reviews, Avg 3.4
2. Orkut - 9 reviews, Avg 4.1
3. Facebook - 12 reviews, Avg 4.3
4. Anyother - 2 reviews, Avg 2

CompanyB:

1. Google - 2 reviews, Avg 3
2. Facebook - 5 reviews, Avg 4

For this I have done

```
    final_list = company_list = []
    websites = Website.objects.select_related().filter(user = user)

    for website in websites:
        company = website.company
        if company is not None and company not in company_list:
            company_list.append(brand)
            company_websites = websites.filter(company = company)
            info = []
            for company_website in company_websites:
                company_type = company_website.website_type
                reviews = Review.objects.filter(company = company, website = company_website)
                no_of_reviews = len(reviews)
                average = reviews.aggregate(Avg('rating'))
                info.append({"type": company_type, "no_of_reviews": no_of_reviews,
                             "average": average['rating__avg']})
            final_list.append({"company": company.name, "stats": info})

```

**There are 2 problems with the code**

1. It is wasting a lot of computation
2. It also somehow appends empty lists in the final\_list (BUGGY)

**FYI:** I believe .annotate() can be used, but I fail to understand how can I use it based on a column, which in my case is (company\_\_name)