title: Is there a django way of grouping records in to groups (groups in a list) and returning a list of ocurrences for each item group?
body: <p>I have the following list, containing the weeks in the year (python - Django):</p>
  
  <pre><code>weeks = list(range(1,53))
  </code></pre>
  
  <p>I have a Project model with date_started and date_registered attributes as follows:</p>
  
  <pre><code>class Project(models.Model):
      from_company = models.ForeignKey(Company,on_delete=models.CASCADE)
      project_name = models.CharField("Nombre de Proyecto", max_length=200,unique=True)
      follow_date = models.DateField("Fecha de Seguimiento", default=timezone.now() + timezone.timedelta(days=5))
      date_registered = models.DateTimeField("Fecha de Registro",auto_now_add=True)
      date_started = models.DateTimeField("Fecha de Inicio",null=True)
      last_modified = models.DateTimeField("Ultima Vez Modificado",auto_now=True)
  </code></pre>
  
  <p>Currently, I'm itterating through each week and get the lenght of the queryset that matches the date_registered__week with the week in the loop, and appending it to a list, like so:</p>
  
  <pre><code>project_active_week = []
  for week in weeks:
              if week is not None:
                  active_projects = [x.project_name for x in Project.objects.filter(date_registered__week = week,date_registered__year = timezone.now().year)]
                  project_active_week.append(len(active_projects))
  </code></pre>
  
  <p>I have several of this stuff going on and my app has become very slow. Is there a way to perform this more efficiently? Database is Sqlite.</p>
  
  <p>Thank you very much for your help!</p>