krzyhub
krzyhub

Reputation: 6540

How can i get indexes of my instances objects?

For example if i want print indexes of this objects:

items = Item.objects.filter(depth=1)

How can i do this?

Upvotes: 0

Views: 132

Answers (1)

Owen Nelson
Owen Nelson

Reputation: 866

If you want to print the positional index of a list/iterator of items (like a queryset), you can do something like the following:

for i, obj in enumerate(items):
    print i, obj

The value of i will be the index of the given model instance.

Upvotes: 1

Related Questions