title: Flask-Sqlalchemy .in_() method not working for me
body: <p>I'm currently working on a project with Flask and SQLAlchemy, basically forum software like discourse but in Python 3.</p>
  
  <p>There are Two models at the moment, Forum and Threads</p>
  
  <p>I've got a Jinja template that should be generating table records of forum threads, please see below.</p>
  
  <pre><code>{% for thread in Forum.ForumThreads.filter_by(TagID.in_(TagsToShow)): %}
      &lt;TR Class="ThreadRecord"&gt;
          &lt;TD&gt;&lt;a href="{{thread.ForumID}}/Thread/{{thread.ThreadID}}"&gt;{{thread.Title}}&lt;/a&gt;&lt;/TD&gt;
          &lt;TD class="ThreadTag{{thread.TagID}}"&gt;{{thread.Tag.Name}}&lt;/TD&gt;
          &lt;TD&gt;{{thread.PostList.count()}}&lt;/TD&gt;
          &lt;TD&gt;{{thread.User.Name}}&lt;/TD&gt;
          &lt;TD&gt;{{thread.CreationDate}}&lt;/TD&gt;
      &lt;/TR&gt;
  {% endfor %}
  </code></pre>
  
  <p>This is called by the following view (slightly simplified).</p>
  
  <pre><code>@app.route('/Forum/&lt;int:URLForumID&gt;/ForumThreads')
      def ThreadsTable(URLForumID):
      TagsToShow = (1,2,3,4)
      Forum = models.Forum.query.filter_by(ForumID=URLForumID).first()
      return flask.render_template('ForumThreads.html', Forum=Forum, TagsToShow=TagsToShow)
  </code></pre>
  
  <p>However, every time I try to run it I get the error "jinja2.exceptions.UndefinedError: 'TagID' is undefined".</p>
  
  <p>I've tried running it with <strong>{% for thread in Forum.ForumThreads.filter_by(TagID=1): %}</strong> and it seems to run fine, so my problem appears to be in how I am calling the .in_() method. I've searched through the <a href="http://docs.sqlalchemy.org/en/rel_0_9/core/sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.in_" rel="nofollow">documentation for SQLalchemy</a> but have been unable to find the answer, would anyone be able to point me in the right direction?</p>
  
  <p>I don't know if it helps, but below are the two stripped down versions of the SQLalchemy models used.</p>
  
  <pre><code>class Forum(db.Model):
      __tablename__ = "Forum"
      ForumID = db.Column(db.Integer, primary_key=True)
      ForumName = db.Column(db.Unicode(20), unique=True, nullable=False)
      CreationDate = db.Column(db.DateTime, default=datetime.datetime.utcnow(), nullable=False)
      ForumThreads = db.relationship("Thread", backref="Forum", lazy='dynamic')
      __table_args__ = {'mysql_engine': 'InnoDB'}
  
  class Thread(db.Model):
      __tablename__ = "Thread"
      ThreadID = db.Column(db.Integer, primary_key=True)
      ForumID = db.Column(db.Integer, db.ForeignKey("Forum.ForumID"), nullable=False)
      Title = db.Column(db.Unicode(100), nullable=False)
      UserID = db.Column(db.Integer, db.ForeignKey("User.UserID"), nullable=False)
      TagID = db.Column(db.Integer, db.ForeignKey("TagTypes.TagID"), nullable=False)
      CreationDate = db.Column(db.DateTime, default=datetime.datetime.utcnow(), nullable=False)
      __table_args__ = (db.ForeignKeyConstraint(['ForumID'], ['Forum.ForumID']),
                    db.ForeignKeyConstraint(['UserID'], ['User.UserID']),
                    db.ForeignKeyConstraint(['TagID'], ['TagTypes.TagID']),
                    {'mysql_engine': 'InnoDB'})
  </code></pre>