Python Django Filter greater than Example

Hi Dev,
Now, let's see tutorial of django filter greater than example. this example will help you python django filter greater than example. we will help you to give example of django filter greater than equal to example. you'll learn django greater than filter.
So, The example related to gt and gte field lookup. Let’s understand how to use the “greater than” and greater than or equal to” operator with the help of an example. we will run the following given code.
let's see bellow example here you will learn python django filter greater than example.
Django Admin Interface:

Example: 1
In this example how to use the “greater than” operator with the help of an example. we are going to select all the database objects whose age is greater than 20. The code for the example is as follows.
views.pyfrom django.http import HttpResponse from base.models import Student def index(request): queryset = Student.objects.filter(age__gt=20).values() print(queryset) return HttpResponse(queryset)Output
[ { 'id': 1, 'name': 'Bhavesh', 'age': 25 }, { 'id': 3, 'name': 'Keval', 'age': 22 }, { 'id': 4, 'name': 'Mehul', 'age': 23 } ]Example: 2
In this second example So, we are using the filter() method and in the method, we have passed “age__gte=20” as an argument.select all the objects from the Student model whose age is greater than or equal to 20
views.pyfrom django.http import HttpResponse from base.models import Student def index(request): queryset = Student.objects.filter(age__gte=20).values() print(queryset) return HttpResponse(queryset)Output
[ { 'id': 1, 'name': 'Bhavesh', 'age': 25 }, { 'id': 2, 'name': 'Nikhil', 'age': 20 }, { 'id': 3, 'name': 'Keval', 'age': 22 }, { 'id': 4, 'name': 'Mehul', 'age': 23 } ]
I Hope It will help you....