The following code works in an application:
user.tweets.order_by(Tweet.message)
The following code works in a jinja2 template:
{% for tweet in user.tweets %}
But the following code fails in a template:
{% for tweet in user.tweets.order_by(Tweet.message) %}
Is there a cleaner way to sort the tweets in a jinja2 template, other than adding the following method to the User
class?
def tweets_by_message(self):
return user.tweets.order_by(Tweet.message)
There is nothing wrong with that method, but adding a little method every time I need a different order doesn't sound right.