[Answer]-Django template sort by 'unrelated' model's field

1👍

You have two errors, both in the template.

Firstly, you’ve put your items with the sorted relationship in a list called itemCollection, but in the template you’re iterating over cart_item instead. This is a very good example of why you should be explicit about what variables you pass to the template, rather than relying on locals().

Secondly, you then iterate over part_list without defining it. You mean item.part_list.

Leave a comment