title: Peewee - invalid literal for int() with base 10: '' when looping over query
body: <p>I'm trying to loop over a Peewee query object and I am getting the following error when I attempt to visit the template where the query is looped over:</p>
  
  <pre><code>ValueError: invalid literal for int() with base 10: ''
  </code></pre>
  
  <p>You'll see below the full traceback and code for both the view function and template. I've even tried simplifying down the template loop to just:</p>
  
  <pre><code>{% for company in companies %} 
      &lt;p&gt;{{ company.company_name }}&lt;/p&gt;
  {% endfor %}
  </code></pre>
  
  <p>and I still get the same error. </p>
  
  <p><strong>Full Traceback</strong></p>
  
  <pre><code>Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Library/Python/2.7/site-packages/flask_login.py", line 758, in decorated_view
    return func(*args, **kwargs)
  File "/Users/wyssuser/Desktop/all_my_projects/new_danish/app/views.py", line 143, in index
    return render_template('new_batch.html', companies=companies)
  File "/Library/Python/2.7/site-packages/flask/templating.py", line 128, in render_template
    context, ctx.app)
  File "/Library/Python/2.7/site-packages/flask/templating.py", line 110, in _render
    rv = template.render(context)
  File "/Library/Python/2.7/site-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Library/Python/2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/wyssuser/Desktop/all_my_projects/new_danish/app/templates/new_batch.html", line 2, in top-level template code
    {% extends "base.html" %}
  File "/Users/wyssuser/Desktop/all_my_projects/new_danish/app/templates/base.html", line 1, in top-level template code
    {% extends "bootstrap/base.html" %}
  File "/Library/Python/2.7/site-packages/flask_bootstrap/templates/bootstrap/base.html", line 1, in top-level template code
    {% block doc -%}
  File "/Library/Python/2.7/site-packages/flask_bootstrap/templates/bootstrap/base.html", line 4, in block "doc"
    {%- block html %}
  File "/Library/Python/2.7/site-packages/flask_bootstrap/templates/bootstrap/base.html", line 20, in block "html"
    {% block body -%}
  File "/Users/wyssuser/Desktop/all_my_projects/new_danish/app/templates/base.html", line 95, in block "body"
    {% block content %}{% endblock %}
  File "/Users/wyssuser/Desktop/all_my_projects/new_danish/app/templates/new_batch.html", line 30, in block "content"
    {% for company in companies %}
  File "/Library/Python/2.7/site-packages/peewee.py", line 1772, in next
    obj = self.iterate()
  File "/Library/Python/2.7/site-packages/peewee.py", line 1760, in iterate
    return self.process_row(row)
  File "/Library/Python/2.7/site-packages/peewee.py", line 1833, in process_row
    setattr(instance, column, func(row[i]))
  File "/Library/Python/2.7/site-packages/peewee.py", line 735, in python_value
    return value if value is None else self.coerce(value)
  ValueError: invalid literal for int() with base 10: ''
  </code></pre>
  
  <p><strong>View code</strong></p>
  
  <pre><code>@app.route('/', methods=("POST", 'GET'))
  @login_required
  def index():
    form = GetClientsForm()
  
    if form.validate_on_submit():
      if form.sectors.data == 'Realtors':
        companies = Realtor.select().where((Realtor.have_contacted != True) &amp; (Realtor.dont_contact_anymore != True))
        return render_template('new_batch.html', companies=companies)
  
      else: #Biotech/Engineering
        companies = Company.select().where((Company.have_contacted != True) &amp; (Company.dont_contact_anymore != True))
        return render_template('new_batch.html', companies=companies)
  </code></pre>
  
  <p><strong>Template code</strong></p>
  
  <pre><code>...
  {% for company in companies %}
      &lt;tr class="company-row {{ company.id }}" data-toggle="collapse" data-target="#{{ company.id }}-info" id="row-{{ company.id }}" data-company-id="{{ company.id }}"&gt;
        &lt;td class="col-md-3 company-name"&gt;
          &lt;input type="text" value="{{ company.company_name }}" id="{{ company.id }}-company-name" class="form-control" name="company-name"&gt;
        &lt;/td&gt;
        &lt;td class="col-md-2 company-website"&gt;
          &lt;div&gt;
            &lt;a href="{{ company.website }}" target="blank_"&gt;{{ company.website }}&lt;/a&gt;
          &lt;/div&gt;
        &lt;/td&gt;
        &lt;td class="col-md-3 company-email"&gt;
          &lt;input type="text" value="{{ company.email_address }}" id="{{ company.id }}-company-email" class="form-control" name="company-email"&gt;
        &lt;/td&gt;
        &lt;td class="col-md-1 company-contact-form"&gt;
          &lt;div class="checkbox"&gt;
            &lt;input type="checkbox" id="{{ company.id }}-contact-form" name="contact-form" data-url='contact_form_company'&gt;
          &lt;/div&gt;
        &lt;/td&gt;
        &lt;td class="col-md-1 contact-company"&gt;
          {{ render_submit('E-mail', class="contact-button", data='data-url=contact_company') }}
        &lt;/td&gt;
        &lt;td class="col-md-1 remove-company"&gt;
          {{ render_submit("Don't Contact", class="dont-contact-button", data='data-url=dont_contact_company') }}
        &lt;/td&gt;
        &lt;td class="col-md-1 company-page"&gt;
          &lt;div&gt;
            &lt;a href="{{ url_for('company_page', company_id=company.id) }}"&gt;{{ render_submit('Company Page') }}&lt;/a&gt;
          &lt;/div&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
  {% endfor %}
  ...
  </code></pre>
  
  <p><strong>Update</strong> - model code</p>
  
  <pre><code>class Company(Model):
    dont_contact_anymore = BooleanField(default=False)
    company_name = CharField()
    website = CharField(unique=True)
    email_address = CharField()
    country = CharField()
    scraped_on = DateTimeField(formats="%m-%d-%Y")
    have_contacted = BooleanField(default=False)
    current_pipeline_phase = IntegerField(default=0)
  
    day_0_message_id = IntegerField()
    day_0_contacted_by = ForeignKeyField(
      rel_model=User,
      related_name='contacted_by_day_0',
      db_column='day_0_contacted_by'
      )
    day_0_emails_contacted = CharField()
    day_0_response = IntegerField()
    day_0_sent = DateTimeField(formats="%m-%d-%Y")
  
    day_5_message_id = IntegerField()
    day_5_contacted_by = ForeignKeyField(
      rel_model=User,
      related_name='contacted_by_day_5',
      db_column='day_5_contacted_by'
      )
    day_5_emails_contacted = CharField()
    day_5_response = IntegerField()
    day_5_sent = DateTimeField(formats="%m-%d-%Y")
  
    day_35_message_id = IntegerField()
    day_35_contacted_by = ForeignKeyField(
      rel_model=User,
      related_name='contacted_by_day_35',
      db_column='day_35_contacted_by'
      )
    day_35_emails_contacted = CharField()
    day_35_response = IntegerField()
    day_35_sent = DateTimeField(formats="%m-%d-%Y")
  
    day_125_message_id = IntegerField()
    day_125_contacted_by = ForeignKeyField(
      rel_model=User,
      related_name='contacted_by_day_125',
      db_column='day_125_contacted_by'
      )
    day_125_emails_contacted = CharField()
    day_125_response = IntegerField()
    day_125_sent = DateTimeField(formats="%m-%d-%Y")
  
    batch = IntegerField()
    sector = CharField()
  
    class Meta:
      database = DATABASE
      order_by = ('have_contacted',)
  
    @classmethod
    def create_company(cls, company_name, website, email_address):
      try:
        with DATABASE.transaction():
          cls.create(company_name=company_name, website=website, email_address=email_address, scraped_on=datetime.now)
          print 'Saved {}'.format(company_name)
      except IntegrityError:
        print '{} already exists in the database'.format(company_name)
  </code></pre>