# Django queryset filter problem

**URL:** <https://forum.djangoproject.com/t/django-queryset-filter-problem/7307>\
**Category:** Using Django\
**Created:** [March 30, 2021, 6:23pm UTC](https://forum.djangoproject.com/t/django-queryset-filter-problem/7307 "2021-03-30T18:23:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![devspectre](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/devspectre/32/3559_2.png) [@devspectre](https://forum.djangoproject.com/u/devspectre)\
**Post date:** [March 30, 2021, 6:23pm UTC](https://forum.djangoproject.com/t/django-queryset-filter-problem/7307/1 "2021-03-30T18:23:23Z")

</div>

Hi!

I need to write a queryset which filters 10 higher values and 10 lower values than a given value.

```auto
class Toy(models.Model):
    name = models.CharField()
    price = models.IntegerField()

```

With given price 56, I want to get a list of 10 toys whose prices are higher than the given value and most close to the given value and the same for the lower values.  
Finally, I want to include the toy with given price as well.

I am not sure how I can filter this out.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![marcorichetta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/marcorichetta/32/26473_2.png) [@marcorichetta](https://forum.djangoproject.com/u/marcorichetta)\
**Post date:** [March 30, 2021, 9:28pm UTC](https://forum.djangoproject.com/t/django-queryset-filter-problem/7307/2 "2021-03-30T21:28:13Z")

</div>

Hi!

Take a look at the 2 last examples of the [cheatsheet](https://docs.djangoproject.com/en/3.1/topics/db/aggregation/#cheat-sheet) with `annotate`, it might give you an idea.

Feel free to post any doubt.

---

<div class="post-metadata">

**Author:** ![devspectre](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/devspectre/32/3559_2.png) [@devspectre](https://forum.djangoproject.com/u/devspectre)\
**Post date:** [March 30, 2021, 9:32pm UTC](https://forum.djangoproject.com/t/django-queryset-filter-problem/7307/3 "2021-03-30T21:32:00Z")

</div>

Thanks @marcorichetta

I think I actually did it as same as in the example. 😃

---

<div class="post-metadata">

**Author:** ![JafferyTech](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jafferytech/32/4177_2.png) [@JafferyTech](https://forum.djangoproject.com/u/JafferyTech)\
**Post date:** [April 9, 2021, 11:49am UTC](https://forum.djangoproject.com/t/django-queryset-filter-problem/7307/4 "2021-04-09T11:49:29Z")

</div>

Hello!! Friends ! I am creating an E-learning Site where I have to create course for teacher …So I successfully Created Course with create view and List view Now …I want to create Sections within the Course Like when teacher hit course title fo to course detail page its work fine…I have also created course detail page succesfully…Now the problem is when User/teacher create subject with Course Selected as a Foreign Key it will display creatd subject in subject list view …but when I choose other course with foreign key .its also showing in List view…I want only display selected course(ForignKey) subject in ListView…Anypne can help?I will also put Screen shot of my problem

 ![addsection](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/7/79c5c7f9527f8c3eac431de29a84f8eb308ee712.png) ![SubjectCreateview|436x422]
