[user_stream.html]

...
<div class="grid-25">
  <h5>Followers</h5>
  <p>{{ user.followers().count() }}</p>
</div>
<div class="grid-25">
  <h5>Following</h5>
  <p>{{ user.following().count() }}</p>
</div>
...

<div class="grid-25">
  {% if current_user.is_authenticated() %}
    {% if user != current_user %}
      {% if not user in current_user.following() %}
        <a href="{{ url_for('follow', username=user.username) }}" class="small">Follow</a>
      {% else %}
        <a href="{{ url_for('unfollow', username=user.username) }}" class="small">Unfollow</a>
      {% endif %}
    {% endif %}
  {% endif %}
</div>
...

Nothing out of the ordinary here.


 Querysets

    @property
    def followers(self):
        """Users that follow the current user."""
        return User.select().join( Relationship, on=Relationship.from_user
	).where( Relationship.to_user == self )

@property
This decorator turns the returned query from the function into a queryset. This means when you call followers from the template you don’t have to call the function such as user.follower(), but you call the queryset directly like so: user.followers.