title: Trouble converting string to int in Django/Python
body: <p>I'm trying to convert a string into an int so that I can keep a running total and would like to be able to output in the django template.</p>
  
  <pre><code>def stats(request):
      stats = []
      players = Player.objects.all()
  
      for player in players:
          player_stats = PlayerStat.objects.filter(player__id=player.pk)
          for n,stat in enumerate(player_stats):
              if n == 0: 
                      passing_completions = stat.passing_completions
              else:
                  passing_completions += stat.passing_completions
  
          stats.append((player.first_name, player.last_name, player.team, passing_completions))
  
      return render_to_response('preps/stats.html', {'stats': stats, })
  </code></pre>
  
  <p>I've tried adding int() around stat.passing_completions but then that just throws the error <code>invalid literal for int() with base 10: ''</code>. </p>
  
  <p>So then I used the <code>isdigit()</code> method to make sure only strings with digits were trying to be converted like this:</p>
  
  <pre><code>for player in players:
      player_stats = PlayerStat.objects.filter(player__id=player.pk)
  
      for n,stat in enumerate(player_stats):
          if n == 0: 
              if stat.passing_completions.isdigit():
                  passing_completions = int(stat.passing_completions)
          else:
              if stat.passing_completions.isdigit():
                  passing_completions += int(stat.passing_completions)
  
      stats.append((player.first_name, player.last_name, player.team, passing_completions))
  </code></pre>
  
  <p>but then I get the error of <code>Caught TypeError while rendering: 'int' object is not iterable</code></p>
  
  <p>model Structure</p>
  
  <pre><code>class PlayerStat(models.Model):
      player = models.ForeignKey(Player)
  
      week_num = models.CharField(
          max_length = 10,
          choices = (('1', 'Sep 2nd',), ('2', 'Sep 9th',), ('3', 'Sep 16th',),('4', 'Sep 23rd',), ('5', 'Sep 30th',), ('6', 'Nov 2nd',),('7', 'Nov 7th',), ('8', 'Nov 14th',), ('9', 'Nov 21st',),('10', 'Nov 28th',), ('11', 'Dec 4th',), ('12', 'Dec 11th',), ),
          blank = True,
          null=True
          )
      rushing_attempts = models.CharField(
          max_length = 100,
          verbose_name = "Rushing Attempts",
          blank=True
          )
      rushing_yards = models.CharField(
          max_length = 100,
          verbose_name = "Rushing Yards",
          blank=True
          )
      rushing_touchdowns = models.CharField(
          max_length = 100,
          verbose_name = "Rushing Touchdowns",
          blank=True
          )
      passing_completions = models.CharField(
          max_length = 100,
          verbose_name = "Passing Completions",
          blank=True
          )
      passing_attempts = models.CharField(
          max_length = 100,
          verbose_name = "Passing Attempts",
          blank=True
          )
      passing_yards = models.CharField(
          max_length = 100,
          verbose_name = "Passing Yards",
          blank=True
          )
      passing_touchdowns = models.CharField(
          max_length = 100,
          verbose_name = "Passing Touchdowns",
          blank=True
          )
      receptions = models.CharField(
          max_length = 100,
          verbose_name = "Receptions",
          blank=True
          )
      receiving_yards = models.CharField(
          max_length = 100,
          verbose_name = "Receiving Yards",
          blank=True
          )
      receiving_touchdowns = models.CharField(
          max_length = 100,
          verbose_name = "Receiving Touchdowns",
          blank=True
          )
  </code></pre>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks</p>