title: working with annotate django
body: <p>What I want to do is pull all the teams that have more than 12 players on it. I am told i need to use .annotate with a count to get it done. I am looking at <a href="https://docs.djangoproject.com/en/1.10/topics/db/aggregation/" rel="nofollow noreferrer">https://docs.djangoproject.com/en/1.10/topics/db/aggregation/</a> but dont understand how to do a query on that and put it into html. I am assuming pull a query and then do html to make it do the right count.</p>
  
  <p>the question for the assignmnt is ...show all teams that have had 12 or more players, past and present. (HINT: Look up the Django annotate function.)</p>
  
  <pre><code>views.py
  
  from django.shortcuts import render, redirect
  from .models import League, Team, Player
  
  from . import team_maker
  
  def index(request):
      context = {
          "leagues": League.objects.all(),
          "teams": Team.objects.all(),
          "players": Player.objects.all(),
          "baseball" : League.objects.filter(sport__contains="Baseball"),
          "women" : League.objects.filter(name__contains="Womens'"),
          "ice" : League.objects.filter(sport__contains="ice"),
          "nofootball" : League.objects.exclude(sport__contains="football"),
          "conferences" : League.objects.filter(name__contains="conference"),
          "atlantic": League.objects.filter(name__contains="Atlantic"),
          "teamdallas": Team.objects.filter(location__contains="Dallas"),
          "raptor": Team.objects.filter(team_name__contains="Raptor"),
          "cityloc": Team.objects.filter(location__contains="city"),
          "startT": Team.objects.filter(team_name__startswith="T"),
          "abc": Team.objects.order_by('location'),
          "cba": Team.objects.order_by('location').reverse(),
          "cooper": Player.objects.filter(last_name="Cooper"),
          "joshua": Player.objects.filter(first_name="Joshua"),
          "nocooper": Player.objects.filter(last_name="Cooper").exclude(first_name="Joshua"),
          "wyatt": Player.objects.filter(first_name="Alexander")|Player.objects.filter(first_name="Wyatt"),
          "atlanticsoccer" : Team.objects.filter(league__name__contains='atlantic', league__sport__contains="soccer"),
          "bostonp" : Player.objects.filter(curr_team__team_name__contains='Penguins'),
          "icbc" : Player.objects.filter(curr_team__league__name__contains='International Collegiate Baseball '),
          "footballlopez" : Player.objects.filter(curr_team__league__name__contains="American Conference of Amateur Football", last_name__contains="lopez"),
          "footballplayer" : Player.objects.filter(curr_team__league__sport__contains="football"),
          "sophia" : Team.objects.filter(curr_players__first_name__contains='sophia'),
          "sophiale" :League.objects.filter(teams__curr_players__first_name__contains='sophia'),
        "notrough" :Player.objects.filter(last_name__contains='Flores').exclude(curr_team__team_name__contains='rough'),
        "sevans" :Team.objects.filter(all_players__first_name__contains='Samuel'),
        "Tiger" :Player.objects.filter(all_teams__team_name__contains='Tiger'),
        "vikings":Player.objects.filter(all_teams__team_name__contains='vikings'),
        "jgray":Team.objects.filter(all_players__first_name__contains='Jacob').exclude(team_name__contains='colts'),
        "joshua":Player.objects.filter(all_teams__league__name__contains='Atlantic Federation of Amateur Baseball')&amp;Player.objects.filter(first_name='Joshua'),
        "num12":Player.objects.annotate(num13=)
  
  
  
      }
  
          return render(request, "leagues/index.html", context)
  
  def make_data(request):
      team_maker.gen_leagues(10)
      team_maker.gen_teams(50)
      team_maker.gen_players(200)
  
      return redirect("index")
  
  models.py
  
  from django.db import models
  
  class League(models.Model):
      name = models.CharField(max_length=50)
      sport = models.CharField(max_length=15)
      created_at = models.DateTimeField(auto_now_add=True)
      updated_at = models.DateTimeField(auto_now=True)
  
  class Team(models.Model):
      location = models.CharField(max_length=50)
      team_name = models.CharField(max_length=50)
      league = models.ForeignKey(League, related_name="teams")
  
  class Player(models.Model):
      first_name = models.CharField(max_length=15)
      last_name = models.CharField(max_length=15)
      curr_team = models.ForeignKey(Team, related_name="curr_players")
      all_teams = models.ManyToManyField(Team, related_name="all_players")
  </code></pre>