lionel
lionel

Reputation: 170

Django - Filter for objects with field that is bigger than limit value

I want to filter for objects whose id is bigger than one that I've specified.

This is what I am looking for:

const LIMIT_ID = 100

bigIdPeople = Person.objects.filter(id > LIMIT_ID)

Is this possible and how should I do this? Thank you!

Upvotes: 1

Views: 2964

Answers (2)

sepulchre01
sepulchre01

Reputation: 1477

Reminder that you need two underscores in order to use gte: Person.objects.filter(id__gte=LIMIT_ID)

Upvotes: 1

user15256253
user15256253

Reputation:

You can do like this:

bigIdPeople = Person.objects.filter(id_gte=LIMIT_ID)
# this means 'greater than or equal to'
# if you want 'greater than', you can change 'gte' to 'gt'.

Upvotes: 2

Related Questions