title: Jinja2/Flask: sort-error when list contains None's
body: <p>I use Flask/Jinja2 to render a simple model to a table. Everything works just fine, but if i try to sort and attribute which can be None, I get a </p>
  
  <pre><code>TypeError: unorderable types: NoneType() &lt; NoneType()
  </code></pre>
  
  <p>I implement the <code>__lt__</code>, <code>__gt__</code> methods to be able to sort my objects.</p>
  
  <p>My first class is a Task-class. It has an foreign key to the Person-class. I wanna sort by the Person-class, but None is a legitimate state of person.</p>
  
  <p>template snippet</p>
  
  <pre><code> {% for t in tasks | sort(attribute=sort_on) %}
  </code></pre>
  
  <p>models.py snippet:</p>
  
  <pre><code>class Person(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(300),nullable=False)
      username = db.Column(db.String(300),nullable=False,unique=True)
      tasks = db.relationship('Task', backref='resource', lazy='dynamic')
  
      def __lt__(self,other):
          if other == None:
              return True
          return self.name.__lt__(other.name)
  
      def __gt__(self,other):
          if other == None:
              return False
          return self.name.__gt__(other.name)
  
  
  class Task(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(300),nullable=False)
      text = db.Column(db.Text)
      prio = db.Column(db.Integer)
      person_id = db.Column(db.Integer, db.ForeignKey('person.id'))
      project_id = db.Column(db.Integer, db.ForeignKey('project.id'),nullable=False)
      planned_days = db.Column(db.Integer)
      done = db.Column(db.Integer)
      state_id = db.Column(db.Integer, db.ForeignKey('state.id'),nullable=False)
      issue = db.Column(db.String(100))
  </code></pre>
  
  <p>Does anybody know how I can fix this??</p>