Tom Carrick
Tom Carrick

Reputation: 6616

django template filter chaning - get last element of last element

So I'm throwing together a basic forum as an example and I want to display in the template the date (and I suppose username) of the last post.

So my first thought was something like this:

topics|last.post_set.all|last.created

Django does not like this and gives me a TemplateSyntaxError:

"Could not parse some characters: topics|last|.post_set.all||last.created".

So I guess I can't chain filters and methods and so like this.

I think I might be on the wrong track here but I'm not sure what else I can do from the template.

Any suggestions other than the obvious "do it in the view"?

Upvotes: 0

Views: 702

Answers (1)

DrTyrsa
DrTyrsa

Reputation: 31951

If you want last item, according to some date, define Meta.get_latest_by in both models and use

topics.latest.post_set.latest.created

Upvotes: 2

Related Questions