B
B
blackbb2018-11-14 16:45:25
Django
blackbb, 2018-11-14 16:45:25

How to compare an object in the list with the previous one in a template?

class Order(models.Model):
    title = models.CharField()
    user = models.ForeignKey(User)

views.py
class OrderListView(ListView):
    model = Order

order_list.html
{% for item in order_list %}
    {{item.title}} - {{item.user}}
{% endfor %}

How to check if the next list object contains the same user as the previous one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2018-11-14
@deliro

itertools.tee + itertools.zip_longest

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question