title: flask-sqlalchemy: Query for records in one table with NO related records in another table (or records of a certain value)
body: <p>I am writing a simple app that helps people call voters. I don't want my volunteers to bug any voter more than once. How can I get a list of voters who have not been called yet? I'm using flask with flask-sqlalchemy.</p>
  
  <p>Voter model:</p>
  
  <pre><code>    class Voter(db.Model):
          id = db.Column(db.Integer, primary_key=True)
          name = db.Column(db.String(80))
          phone = db.Column(db.String(20))
          vanid = db.Column(db.String(20))
          address = db.Column(db.String(255))
          city = db.Column(db.String(255))
          zip_code = db.Column(db.String(20))
          lat  = db.Column(db.Float)
          lng = db.Column(db.Float)
          ...
  </code></pre>
  
  <p>Calls Model:</p>
  
  <pre><code>    class Call(db.Model):
          id = db.Column(db.Integer, primary_key=True)
          voter_id = db.Column(db.Integer, db.ForeignKey('voter.id'))
          voter = db.relationship('Voter', backref=db.backref('calls', lazy='dynamic'))
          user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
          user = db.relationship('User', backref=db.backref('calls', lazy='dynamic'))
          time = db.Column(db.DateTime)
          status_code = db.Column(db.String(20))
          ...
  </code></pre>
  
  <p>call.status_code will contain values such as completed,busy,wrong_number, etc.</p>
  
  <p>I want to get a list of all voters who are eligible to be called so that I can pick one to serve to the volunteer. (ie. call.status_code != completed etc. OR has no related call records)</p>
  
  <p>If were to do this in raw SQL I would likely do:</p>
  
  <pre><code>Select [whatever]
  FROM Voter v
  LEFT JOIN Call c on c.voter_id = v.id
  WHERE c.status_code IS NULL OR c.status_code = 'busy'
  </code></pre>
  
  <p>I can't figure it out in sqlalchemy. Any insights?</p>