[Answer]-Django: Using same object how to show 2 different results in django template?

1👍

Template is used only to display given data. If you want to manipulate data, you have to do this in view. It’ll be a lot easier, as you can use normal python syntax.

You can use something like:

all_data = <object_name>.objects.all()
unique_data = list(set(all_data))

UPDATE

If you want to do this on frontend, I would recommend using Lodash library.

But you can of course do it in plain JavaScript:

var all_data = ...;
var unique_data = [];
for (i = 0; i < all_data.length; i++) {
    if (unique_data.indexOf(all_data[i]) < 0) unique_data.push(all_data[i]);
}

Leave a comment