Django Objects Filter Case Insensitive Example

Published On: 23/08/2022 | Category: Django


Hi Dev,

This tutorial is focused on django objects filter case insensitive. This tutorial will give you simple example of django objects filter case insensitive example. you will learn django contains case insensitive. you can see django contains case-insensitive example. Let's see bellow example how to query case-insensitive data in django orm.

Django iexact and icontains return case-insensitive exact match. If the value provided for comparison is None, it will be interpreted as an SQL NULL.

You can use these examples with django3 (Django 3) version.

let's see bellow example here you will learn python Django filter distinct example.

Django Admin Interface:



Example

In this example we will use the same Employee model. And here is the example of the iexact method.

views.py
from django.http import HttpResponse
from core.models import Member

def index(request):
    queryset = Employee.objects.filter(firstname__iexact='bhavesh').values()
    print(queryset)

    return HttpResponse(queryset)
Output
[
    {
        'id': 1,
        'firstname': 'Bhavesh',
        'lastname': 'Sonagra'
    }
]
Example

In this example we will use the same Employee model. And here is the example of the icontains method.

views.py
from django.http import HttpResponse
from core.models import Member

def index(request):
    queryset = Employee.objects.filter(firstname__icontains='bhavesh').values()
    print(queryset)

    return HttpResponse(queryset)
Output
[
    {
        'id': 1,
        'firstname': 'Bhavesh',
        'lastname': 'Sonagra'
    }
]

I Hope It will help you....