43Tesseracts
43Tesseracts

Reputation: 4937

get a list of a specific attribute from a list of model objects in a Django template

Is there a way to get a list of a specific attribute from a list of model objects, {{ object_list }} using the Django Template Language?

Similar to this in Python? [o.my_attr for o in object_list]

Upvotes: 0

Views: 94

Answers (1)

veggie1
veggie1

Reputation: 747

You can't really do list comprehensions inside Django templates. You should do this in your view and pass the list in your context to the template.

Upvotes: 1

Related Questions