# Problem with looping through Users

**URL:** <https://forum.djangoproject.com/t/problem-with-looping-through-users/25570>\
**Category:** Using the ORM\
**Created:** [November 22, 2023, 10:17pm UTC](https://forum.djangoproject.com/t/problem-with-looping-through-users/25570 "2023-11-22T22:17:56Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 23, 2023, 3:17am UTC](https://forum.djangoproject.com/t/problem-with-looping-through-users/25570/4 "2023-11-23T03:17:36Z")

</div>

Pulling what I think is the best example from the cheat sheet:

```auto
>>> above_5 = Count("book", filter=Q(book __rating__ gt=5))
>>> below_5 = Count("book", filter=Q(book __rating__ lte=5))
>>> pubs = Publisher.objects.annotate(below_5=below_5).annotate(above_5=above_5)

```

I think you’re going to end up with something like:

```auto
avg50=Avg('scores__match_score', filter=Q(scores__range_distance="50"))
avg100=Avg('scores__match_score', filter=Q(scores__range_distance="100"))
user_list = User.objects.annotate(avg50=avg50, avg100=avg100)

```

Note: I’m winging this, there may be an error or 10 here - but it should be enough to get you started.

---

_[View the full topic](https://forum.djangoproject.com/t/problem-with-looping-through-users/25570)._
